473,230 Members | 1,511 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,230 software developers and data experts.

XmlNode.SelectNodes, order of nodes

If I execute XmlNode.SelectNodes("some xpath query") and then use foreach to
iterate over it.
Will it guaratee that the order of nodes I get will be same as the order of
nodes in the original xml document?

Can someone point me to a document which states that the order is (or is
not) guarateened (I could not find any when i did my search on msdn).

This is very crucial to our design, otherwise I will have to add a
"sequence" attribute and then order by the sequence.

Thanks in advance.
--
Vikram Vamshi
Database Engineer
Eclipsys Corporation
Jun 12 '06 #1
8 12033


Vikram Vamshi wrote:
If I execute XmlNode.SelectNodes("some xpath query") and then use foreach to
iterate over it.
Will it guaratee that the order of nodes I get will be same as the order of
nodes in the original xml document?


I think XPath rules will apply so on e.g. the child axis the nodes will
be in document order, on e.g. the preceding-sibling axis the nodes will
be in reversed document order.

See the XPath specification <http://www.w3.org/TR/xpath#axes>, an
excerpt says:
"An axis is either a forward axis or a reverse axis. An axis that
only ever contains the context node or nodes that are after the context
node in document order is a forward axis. An axis that only ever
contains the context node or nodes that are before the context node in
document order is a reverse axis. Thus, the ancestor, ancestor-or-self,
preceding, and preceding-sibling axes are reverse axes; all other axes
are forward axes. Since the self axis always contains at most one node,
it makes no difference whether it is a forward or reverse axis."
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jun 12 '06 #2
Martin,
I did read the document, from what I understand it says that the nodes in
the node-set are based upon the axis that you select.
Howerver it does not impose any ordering on the nodes within the final
node-set.
So the 'axis' simply acts like a filtering mechanism. Did I misinterpret it?

Thanks for taking your time to respond.

Vikram
--
Vikram Vamshi
Database Engineer
Eclipsys Corporation
"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...


Vikram Vamshi wrote:
If I execute XmlNode.SelectNodes("some xpath query") and then use foreach
to iterate over it.
Will it guaratee that the order of nodes I get will be same as the order
of nodes in the original xml document?


I think XPath rules will apply so on e.g. the child axis the nodes will be
in document order, on e.g. the preceding-sibling axis the nodes will be in
reversed document order.

See the XPath specification <http://www.w3.org/TR/xpath#axes>, an excerpt
says:
"An axis is either a forward axis or a reverse axis. An axis that only
ever contains the context node or nodes that are after the context node in
document order is a forward axis. An axis that only ever contains the
context node or nodes that are before the context node in document order
is a reverse axis. Thus, the ancestor, ancestor-or-self, preceding, and
preceding-sibling axes are reverse axes; all other axes are forward axes.
Since the self axis always contains at most one node, it makes no
difference whether it is a forward or reverse axis."
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Jun 12 '06 #3
Vikram Vamshi wrote:
If I execute XmlNode.SelectNodes("some xpath query") and then use foreach to
iterate over it.
Will it guaratee that the order of nodes I get will be same as the order of
nodes in the original xml document?

Can someone point me to a document which states that the order is (or is
not) guarateened (I could not find any when i did my search on msdn).

This is very crucial to our design, otherwise I will have to add a
"sequence" attribute and then order by the sequence.


http://msdn2.microsoft.com/en-us/mic...lectnodes.aspx

"Returns a XMLNodes collection that represents all the nodes that match
a specified XPath string in the order in which they appear."
--
Oleg Tkachenko [XML MVP, MCAD]
http://www.XmlLab.Net | http://www.XLinq.Net | http://blog.tkachenko.com
Jun 13 '06 #4
That is from the word interop documentation, do you think the same will hold
true for the .net 2.0 framework.

--
Vikram Vamshi
Database Engineer
Eclipsys Corporation
"Oleg Tkachenko [MVP]" <so**@body.com> wrote in message
news:44**************@body.com...
Vikram Vamshi wrote:
If I execute XmlNode.SelectNodes("some xpath query") and then use foreach
to iterate over it.
Will it guaratee that the order of nodes I get will be same as the order
of nodes in the original xml document?

Can someone point me to a document which states that the order is (or is
not) guarateened (I could not find any when i did my search on msdn).

This is very crucial to our design, otherwise I will have to add a
"sequence" attribute and then order by the sequence.


http://msdn2.microsoft.com/en-us/mic...lectnodes.aspx

"Returns a XMLNodes collection that represents all the nodes that match a
specified XPath string in the order in which they appear."
--
Oleg Tkachenko [XML MVP, MCAD]
http://www.XmlLab.Net | http://www.XLinq.Net | http://blog.tkachenko.com

Jun 13 '06 #5
Vikram Vamshi wrote:
That is from the word interop documentation, do you think the same will hold
true for the .net 2.0 framework.


Yes. But if your whole design depends on this feature you better sort
selected nodes explicitly. XmlNode.SelectNodes is just a wrapper for
XPathNavigator.Select, so instead SelectNodes use XPathNavigator,
compiled XPathExpression and AddSort() method to sort nodes by preceding
nodes count.

--
Oleg Tkachenko [XML MVP, MCAD]
http://www.XmlLab.Net | http://www.XLinq.Net | http://blog.tkachenko.com
Jun 14 '06 #6
Thanks!!!

--
Vikram Vamshi
Database Engineer
Eclipsys Corporation
"Oleg Tkachenko [MVP]" <so**@body.com> wrote in message
news:44**************@body.com...
Vikram Vamshi wrote:
That is from the word interop documentation, do you think the same will
hold true for the .net 2.0 framework.


Yes. But if your whole design depends on this feature you better sort
selected nodes explicitly. XmlNode.SelectNodes is just a wrapper for
XPathNavigator.Select, so instead SelectNodes use XPathNavigator, compiled
XPathExpression and AddSort() method to sort nodes by preceding nodes
count.

--
Oleg Tkachenko [XML MVP, MCAD]
http://www.XmlLab.Net | http://www.XLinq.Net | http://blog.tkachenko.com

Jun 15 '06 #7

Hi, Nice Replies those are worth ful..

Please have a look at my blog

http://dotnethangout.blogspot.com/20...ml-in-net.html


*** Sent via Developersdex http://www.developersdex.com ***
Feb 27 '07 #8

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

Similar topics

1
by: Praveen Naregal | last post by:
hello all, I have a problem. I have an XML file like below one.I want to loop through node by node and store or display the data . Can anybody give me a sample piece of c# code? Thanks &...
3
by: Adam Smith | last post by:
If I use XmlNode.SelectNodes() in my program and then use foreach XmlNode node in XmlNodeList am I guaranteed to get the nodes in the order in which they appear in the original xml document source?...
2
by: microsoft | last post by:
I have a very "flat" doc structure like this <root> <one> <two> <three> ... n <=100 </root>
0
by: david.k.land | last post by:
I have an XML document that I'm looping through and modifying as I go. Some nodes have to be deleted and I don't want to process their children after deleting the node. If my XML structure looks...
0
by: Jeppe BS | last post by:
I got this simple XML file which im using the SelectNodes funktion on and it works well. Then i got this other XML file with the same structure as the first one but every sub node contains a lot...
5
by: Newbie | last post by:
The answer to this is probably obvious, but I'm somewhat new to XSLT and can't find it. I need to sort a set of nodes within a document, e.g. <A> <B/> <C> <D>3</D> <D>2</D>
2
by: JS | last post by:
Hi there, How do I count the number of <Itemnodes for each <Messagein the following xml document? (Xml Document) <Message> <Order> <Item>1</Item> <Item>2</Item>
1
by: =?Utf-8?B?cGVsZWdrMQ==?= | last post by:
i have an xml for example: <xml> <data> <var>xxx</var> </data> <tip> <tips active="1">345</tips> <tips active="1">retertert</tips> <tips active="1">fdgdfg</tips> <tips...
3
Shinobi
by: Shinobi | last post by:
I am trying to delete a node in xml. Nothing is worked correctly. Here is XML <cat> <category> <id>1</id> <name>Architecture</name> </category> <category> <id>2</id>
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

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.