XPathNavigator.HasChildren always returns true??

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
XPathNavigator.HasChildren returns true on nodes for which I think it should return false. In fact I have never seen it return false. For example, I have the following XML in a local file called imagedataDummy.xml:
<?xml version="1.0" encoding="utf-8" ?><br/>
<graphicdata><br/>
<graphic><br/>
<graphicid>someKindOfGUID001</graphicid><br/>
<createddatetime>4/12/2011 3:34:12 PM</createddatetime><br/>
<weblocation>http://someFolder/someGuid101_web.jpg</weblocation><br/>
<thumblocation>http://someFolder/someGuid101_thumb.jpg</thumblocation><br/>
<facetcollection><br/>
<facetid>hybrids</facetid><br/>
<facetid>jones</facetid><br/>
</facetcollection><br/>
</graphic><br/>
<graphic><br/>
<graphicid>someKindOfGUID002</graphicid><br/>
<createddatetime>4/14/2011 9:08:52 PM</createddatetime><br/>
<weblocation>http://someFolder/someGuid102_web.jpg</weblocation><br/>
<thumblocation>http://someFolder/someGuid102_thumb.jpg</thumblocation><br/>
<facetcollection><br/>
<facetid>programming</facetid><br/>
<facetid>education</facetid><br/>
<facetid>exploration</facetid><br/>
<facetid>consumer</facetid><br/>
</facetcollection><br/>
</graphic><br/>
</graphicdata>
I tried using this code (borrowed and adapted from posts of others) to gain an understanding of how XPathNavigator.HasChildren works:
string myString;<br/>
XPathDocument document = new XPathDocument("imagedataDummy.xml");<br/>
XPathNavigator navigator = document.CreateNavigator();<br/>
XPathNodeIterator iterator = navigator.Select("/graphicdata/graphic/graphicid");<br/>
while (iterator.MoveNext())<br/>
{<br/>
XPathNavigator nav2 = iterator.Current;<br/>
myString = nav2.LocalName + ": ";<br/>
myString += nav2.Value + " - HasChildren: ";<br/>
myString += nav2.HasChildren;<br/>
MessageBox.Show(myString);<br/>
}
The output from the above indicates that the graphicid node has children. That doesnt make sense to me. Since I dont see any nodes hierarchically under graphicid I expect HasChildren to be false. Why is it true? Can you see some
mistake in my code or in my thinking?
Thanks,
Larry<br/>
<span style="font-family:Consolas; color:#a31515; font-size:x-small
<span style="font-family:Consolas; color:#a31515; font-size:x-small
<span style="font-family:Consolas; color:#a31515; font-size:x-small





View the full article
 
Back
Top