Removing preprocessing instructions from an XML in c#

后端 未结 2 840
暖寄归人
暖寄归人 2021-01-26 04:33

How can i remove preprocessing instructions from an XML in a greener way? suppose that I have this xml in a string variable (which is a property of a class),I wante

2条回答
  •  星月不相逢
    2021-01-26 05:07

    If you can load it in an XmlDocument: FirstChild returns the node, and NextSibling returns the rest.

    XmlDocument doc = new XmlDocument();
    doc.Load(path);
    XmlNode node = doc.FirstChild.NextSibling;
    

    Edit: Your xml looks a lot like the example on msdn for XPathNavigator.Select. Have you tried using that?

    Edit2: You can get the name of the top level element using:

    string topLevelNode = doc.DocumentElement.Name;
    

提交回复
热议问题