How do I get a NameTable from an XDocument?

前端 未结 4 1841
-上瘾入骨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

    You need to shove the XML through an XmlReader and use the XmlReader's NameTable property.

    If you already have Xml you are loading into an XDocument then make sure you use an XmlReader to load the XDocument:-

    XmlReader reader = new XmlTextReader(someStream);
    XDocument doc = XDocument.Load(reader);
    XmlNameTable table = reader.NameTable;
    

    If you are building Xml from scratch with XDocument you will need to call XDocument's CreateReader method then have something consume the reader. Once the reader has be used (say loading another XDocument but better would be some do nothing sink which just causes the reader to run through the XDocument's contents) you can retrieve the NameTable.

提交回复
热议问题