> I have a function that reads a nodes 'InnerText'. But when the node has
> childs 'InnerText' includes that childs text to. Is there a way to select
> the value from the node but not from the child?
You can easily iterate over the ChildNodes and assemble the direct
content of child text nodes:
public static string GetChildText (XmlNode node) {
string text = "";
foreach (XmlNode child in node.ChildNodes) {
if (child.NodeType == XmlNodeType.Text) {
text += child.Value;
}
}
return text;
}
Then use it e.g.
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(@"test2004092801.xml");
XmlNodeList nodeList = xmlDocument.GetElementsByTagName("*");
foreach (XmlNode node in nodeList) {
Console.WriteLine("Text is:\r\n{0}\r\n------------\r\n",
GetChildText(node));
}

Signature
Martin Honnen
http://JavaScript.FAQTs.com/
MA - 28 Sep 2004 13:12 GMT
>> I have a function that reads a nodes 'InnerText'. But when the node has
>> childs 'InnerText' includes that childs text to. Is there a way to select
[quoted text clipped - 22 lines]
> GetChildText(node));
> }
Ok!
I?ll try that.
Thanks for youre answer!!
/Marre