468,272 Members | 2,167 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,272 developers. It's quick & easy.

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 11485


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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Praveen Naregal | last post: by
3 posts views Thread by Adam Smith | last post: by
reply views Thread by david.k.land | last post: by
reply views Thread by Jeppe BS | last post: by
5 posts views Thread by Newbie | last post: by
2 posts views Thread by JS | last post: by
1 post views Thread by =?Utf-8?B?cGVsZWdrMQ==?= | last post: by
Shinobi
3 posts views Thread by Shinobi | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.