How do I get the XML root node with C#?

前端 未结 5 610
天命终不由人
天命终不由人 2020-12-03 02:31

I know that it\'s possible to get any XML node using C# if you know the node name, but I want to get the root node so that I can find out the name. Is this possible?

5条回答
  •  再見小時候
    2020-12-03 03:03

    Root node is the DocumentElement property of XmlDocument

    XmlElement root = xmlDoc.DocumentElement
    

    If you only have the node, you can get the root node by

    XmlElement root = xmlNode.OwnerDocument.DocumentElement
    

提交回复
热议问题