XmlNode - Retrieve Value of a node


I’m trying to load data from XML-file using System.Xml and XmlNode.
For example:

XmlNode NodeData = getNodeData();
Debug.Log(NodeData.SelectSingleNode("Dirname").Value); //shows nothing
Debug.Log(NodeData.SelectSingleNode("Dirname").InnerText); //shows value inside Dirname text as expected

I cannot use InnerText because it returns also data of child nodes.
What is stranger - Name parameter works fine, but Value - isn’t working.


What Value will return depends on the type of XmlNode. For example, for XmlText it will return the text content of the node. Keep in mind that the text content of a node is a node itself of type XmlText (subclass of XmlNode), so if you’re trying to get the value of the following node:


and you don’t want to use InnerText, you can use the following code: