How do I get the text that is within an XmlNode? See below:
XmlNodeList nodes = rootNode.SelectNodes("descendant::*");
for (int i = 0; i < nodes.Count; i++)
{
XmlNode node = nodes.Item(i);
//TODO: Display only the text of only this node,
// not a concatenation of the text in all child nodes provided by InnerText
}
And what I ultimately want to do is preppend “HELP: ” to the text in each node.
The simplest way would probably be to iterate over all the direct children of the node (using
ChildNodes) and test theNodeTypeof each one to see if it’sTextorCDATA. Don’t forget that there may be multiple text nodes.(Just as an FYI, if you can use .NET 3.5, LINQ to XML is a lot nicer to use.)