Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / February 2007

Tip: Looking for answers? Try searching our database.

XmlNode.SelectNodes, order of nodes

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Vikram Vamshi - 12 Jun 2006 17:29 GMT
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.
Signature

Vikram Vamshi
Database Engineer
Eclipsys Corporation

Martin Honnen - 12 Jun 2006 18:17 GMT
> 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."

Signature

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

Vikram Vamshi - 12 Jun 2006 23:58 GMT
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
Signature

Vikram Vamshi
Database Engineer
Eclipsys Corporation

>
>> If I execute XmlNode.SelectNodes("some xpath query") and then use foreach
[quoted text clipped - 16 lines]
> Since the self axis always contains at most one node, it makes no
> difference whether it is a forward or reverse axis."
Oleg Tkachenko [MVP] - 13 Jun 2006 09:36 GMT
> If I execute XmlNode.SelectNodes("some xpath query") and then use foreach to
> iterate over it.
[quoted text clipped - 6 lines]
> 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/microsoft.office.interop.word.xmlnode.selectnod
es.aspx


"Returns a XMLNodes collection that represents all the nodes that match
a specified XPath string in the order in which they appear."

Signature

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

Vikram Vamshi - 13 Jun 2006 16:22 GMT
That is from the word interop documentation, do you think the same will hold
true for the .net 2.0 framework.

Signature

Vikram Vamshi
Database Engineer
Eclipsys Corporation

>> If I execute XmlNode.SelectNodes("some xpath query") and then use foreach
>> to iterate over it.
[quoted text clipped - 11 lines]
> "Returns a XMLNodes collection that represents all the nodes that match a
> specified XPath string in the order in which they appear."
Oleg Tkachenko [MVP] - 14 Jun 2006 09:21 GMT
> 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.

Signature

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

Vikram Vamshi - 15 Jun 2006 15:53 GMT
Thanks!!!

Signature

Vikram Vamshi
Database Engineer
Eclipsys Corporation

>> That is from the word interop documentation, do you think the same will
>> hold true for the .net 2.0 framework.
[quoted text clipped - 4 lines]
> XPathExpression and AddSort() method to sort nodes by preceding nodes
> count.
Nagendra Kumar - 27 Feb 2007 18:35 GMT
Hi, Nice Replies those are worth ful..

Please have a look at my blog

http://dotnethangout.blogspot.com/2007/02/xml-in-net.html
Nagendra Kumar - 27 Feb 2007 18:37 GMT
Please Visit

http://dotnethangout.blogspot.com/2007/02/xml-in-net.html

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.