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.
Check this
also you might check what options you get when you write "reader."
xml file
and reader really basic but fast
Search the node's children for a node with
NodeType
ofText
, and use theValue
property of that node.Note that you can also select text nodes with XPath by using the
text()
node-type test.The simplest way would probably be to iterate over all the direct children of the node (using
ChildNodes
) and test theNodeType
of each one to see if it'sText
orCDATA
. 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.)
you can read the InnerText property of xmlnode read
node.InnerText