473,387 Members | 1,476 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,387 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 12051


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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.