Groups | Blog | Home
all groups > dotnet xml > march 2005 >

dotnet xml : Question about System.Xml.XmlDocument.SelectNodes


Michael H
3/5/2005 1:11:08 AM
Hello group,


I have a some xml that looks like this below:

<tuneRequests ct="3" xmlns:sql="urn:schemas-microsoft-com:xml-sql"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<tr xsi:type="trGenericType" number="2">

<s name="KATU" call_sign="KATU" affiliation="ABC Affiliate"
id="28455700" ppv="0" />

</tr>

<tr xsi:type="trGenericType" number="3">

<s name="KOAB" call_sign="KOAB" affiliation="PBS Affiliate"
id="28460723" ppv="0" />

</tr>

<tr xsi:type="trGenericType" number="6">

<s name="KOIN" call_sign="KOIN" affiliation="CBS Affiliate"
id="28455365" ppv="0" />

</tr>

</tuneRequests>



If I use code as this to populate an array with the value from the
<tr> element:

// doc is an instance of XmlDocument

foreach (node in doc.SelectNodes(@"tuneRequests/tr") ) )
....


then use this code to populate a different array

foreach (node in doc.SelectNodes(@"tuneRequests/tr/s") ) )
....


Is it guaranteed that nodes will be returned in the same order,
top-to-bottom as they appear in the xml document for both
SelectNodes() usages?

I'd like to use this simple code to match the channel number in an
<tr> with the name, call_sign, and affiliation attributes of the
nested <s> element with these two simple foreach structures.



Thanks for any help,


Michael Hughes - Silverton, Oregon
http://wou.ath.cx/Trivia
http://wou.ath.cx/AmateurRadio


Martin Honnen
3/5/2005 12:48:33 PM


[quoted text, click to view]


[quoted text, click to view]

Yes, you get the nodes in document order.
But it could be more efficient to use
foreach (node in doc.SelectNodes(@"tuneRequests/tr")) {
foreach (node2 in node.SelectNodes(@"s"))
that way you avoid that the XPath implementation has to do the same work
of finding tuneRequests/tr twice.



--

Martin Honnen
Michael H
3/5/2005 3:45:00 PM
On Sat, 05 Mar 2005 12:48:33 +0100, Martin Honnen <mahotrash@yahoo.de>
[quoted text, click to view]

Thanks a lot Martin,

I don't have a lot of experience w/ xpath and xml as of yet. Your
suggestion looks a lot better than the way I had planned.

Auf wedersehen,


Michael Hughes - Silverton, Oregon
http://wou.ath.cx/Trivia
http://wou.ath.cx/AmateurRadio

AddThis Social Bookmark Button