add namespace using xmlnamespacemanager in C#

后端 未结 2 1291
攒了一身酷
攒了一身酷 2021-01-11 12:40

I am trying to read the data from XML File. In this elements are prefixed with \'app\' and \'gml\' text. because of these prefixes I am unable to read the data. For this I a

2条回答
  •  隐瞒了意图╮
    2021-01-11 13:26

    Something like:

    var doc = new XmlDocument();
    doc.Load(source);
    var nsmgr = new XmlNamespaceManager(doc.NameTable);
    nsmgr.AddNamespace("app", "http://www.weather.gov/forecasts/xml/OGC_services");
    var firstPoint = doc.SelectSingleNode("//app:Forecast_Gml2Point", nsmgr);
    

    Note that the namespace aliases are merely conveniences, and don't have to match between the document and the namespace-manager - but it is probably easier if they do.

提交回复
热议问题