Reputation: 1415
I am new to XPath.
Using C# I am trying to read the XML file which has a parent node and multiple child nodes
With XPathNavigator, I do a Select on root/parent and assign this value to XPathNodeIterator
XPathNodeIterator ni = _xpathNavigator.Select(theTag);
Then I move to Next When I use ni.Current.Value
I get text value from Parent as well as both Child1 and Child2
What I want to get is the value of Parent only
The OuterText is giving similar results.
Anybody aware of how to get this working?
Upvotes: 1
Views: 731
Reputation: 11
I assume you have some xml such as:
<root>
<outer>
outerValue
<inner1>innerValue1</inner1>
<inner2>innerValue2</inner2>
</outer>
</root>
and you're seeing "outerValueinnerValue1innerValue2" as the returned value of /outer.
I don't believe there is any property on the object that will give you outerValue alone. Obviously you could iterate through the child nodes and remove their values from the concat'd string but thats horrible.
Probably best to add a new child node to your xml eg.
<root>
<outer>
<value>outerValue</value>
<inner1>innerValue1</inner1>
<inner2>innerValue2</inner2>
</outer>
</root>
Upvotes: 1