473,473 Members | 1,900 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Question about System.Xml.XmlDocument.SelectNodes

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

Nov 12 '05 #1
2 1737


Michael H wrote:

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?


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
http://JavaScript.FAQTs.com/
Nov 12 '05 #2
On Sat, 05 Mar 2005 12:48:33 +0100, Martin Honnen <ma*******@yahoo.de>
wrote:


Michael H wrote:

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?


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.


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
Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: awong | last post by:
Hi there, I was trying to convert the following VB6 code to VB.NET. But I can't find a corresponding System.XML object for MSXML IXMLDOMSelection. I am thinking to use System.XML XMLNodeList...
5
by: Markus Stehle | last post by:
Hi all! I want to remove a node from a nodelist by using RemoveChild. I'm using the following code: XmlNode root = Xml.DocumentElement; XmlNodeList items = root.SelectNodes("Item"); XmlNode...
19
by: Derek Martin | last post by:
Hi there, I have been playing with sorting my arraylist and having some troubles. Maybe just going about it wrong. My arraylist contains objects and one of the members of the object is 'name.' I...
1
by: =?Utf-8?B?RGF2aWRHQg==?= | last post by:
OK, so I've created and loaded an XMLDocument object. But how do I go about using it? Specifically, how do I: 1) move to the first node (I assume I start on it when I load the XML?) 2) move to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.