Groups | Blog | Home
all groups > dotnet xml > december 2003 >

dotnet xml : Problem reading the xmlelement value


Michael Søndergaard
12/7/2003 8:53:20 PM
I am trying to read all orders element, which have the attribute
Phase="Reorganize". I am using the following code on the xml document.

private void LoadPhase (XmlDocument Doc, TreeNode Parent, Phase OrderPhase)
{
XmlNodeList Nodes =
Doc.SelectNodes("/OrderFile/Orders/Order[@Phase='Reorganize']");
foreach (XmlElement Node in Nodes)
{
string S = Node.InnerText;
}
}

<?xml version="1.0" encoding="utf-8"?>
<OrderFile Version="1.0">
<Orders>
<Order Phase="Reorganize">DA-(1)
<PhaseError>I dont want this text</PhaseError>
</Order>
<Order UniqueId="1" Phase="Politics">DPR-(2)</Order>
</Orders>
</OrderFile>

My problem is that the Node.InnerText gives me all the following test
"DA-(1)<PhaseError>I dont want this text</PhaseError>, What I need is the
"DA-(1)" part.

How do only read the current elements value and not all it childs nodes?

I checked all the properties of the Node using the debugger, but apparently
none of them contains only the element own value

Michael Søndergaard


Oleg Tkachenko
12/7/2003 10:25:46 PM
[quoted text, click to view]

In XPath data model element's string value is concatenation of values of
descendant text nodes - exactly what you get. What you want is first
text node child of Order element -
/OrderFile/Orders/Order[@Phase='Reorganize']/text()[1]
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel
AddThis Social Bookmark Button