XmlNode.InnerText

Posted by Jonathan.Peppers on Stack Overflow See other posts from Stack Overflow or by Jonathan.Peppers
Published on 2011-01-17T15:38:27Z Indexed on 2011/01/17 15:53 UTC
Read the original article Hit count: 187

Filed under:
|
|

We have XML like so:

<Example>
  <Node>Some text here
    <ChildNode>Child 1</ChildNode>
    <ChildNode>Child 2</ChildNode>
  </Node>
</Example>

We are using XmlDocument to parse this.

When we have the XmlNode of the Node element, XmlNode.InnerText returns us this:

"Some text hereChild 1Child2"

How can we get the inner text of the Node element without the child nodes' inner text? We don't really want to use any Regex or string splitting to accomplish this.

Note: We also don't want to switch to using a different set of classes to parse this XML, it would be too much of a code change.

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET