How do I get a NameTable from an XDocument?

前端 未结 4 1869
-上瘾入骨i
-上瘾入骨i 2021-01-01 08:58

How do I get a NameTable from an XDocument?

It doesn\'t seem to have the NameTable property that XmlDocument has.

EDIT: Judging by the lack of an answer I\'m

4条回答
  •  我在风中等你
    2021-01-01 09:04

    I did it like this:

    //Get the data into the XDoc
    XDocument doc = XDocument.Parse(data);
    //Grab the reader
    var reader = doc.CreateReader();
    //Set the root
    var root = doc.Root;
    //Use the reader NameTable
    var namespaceManager = new XmlNamespaceManager(reader.NameTable);
    //Add the GeoRSS NS
    namespaceManager.AddNamespace("georss", "http://www.georss.org/georss");  
    //Do something with it
    Debug.WriteLine(root.XPathSelectElement("//georss:point", namespaceManager).Value);  
    

    Matt

提交回复
热议问题