XmlNode.SelectNodes, order of nodes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Vikram Vamshi

    #1

    XmlNode.SelectNodes, order of nodes

    If I execute XmlNode.SelectN odes("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


  • Martin Honnen

    #2
    Re: XmlNode.SelectN odes, order of nodes



    Vikram Vamshi wrote:[color=blue]
    > If I execute XmlNode.SelectN odes("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?[/color]

    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/

    Comment

    • Vikram Vamshi

      #3
      Re: XmlNode.SelectN odes, order of nodes

      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" <mahotrash@yaho o.de> wrote in message
      news:%237RNIQkj GHA.1272@TK2MSF TNGP03.phx.gbl. ..[color=blue]
      >
      >
      > Vikram Vamshi wrote:[color=green]
      >> If I execute XmlNode.SelectN odes("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?[/color]
      >
      > 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/[/color]


      Comment

      • Oleg Tkachenko [MVP]

        #4
        Re: XmlNode.SelectN odes, order of nodes

        Vikram Vamshi wrote:[color=blue]
        > If I execute XmlNode.SelectN odes("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.[/color]

        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

        Comment

        • Vikram Vamshi

          #5
          Re: XmlNode.SelectN odes, order of nodes

          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]" <some@body.co m> wrote in message
          news:448E85BC.2 020608@body.com ...[color=blue]
          > Vikram Vamshi wrote:[color=green]
          >> If I execute XmlNode.SelectN odes("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.[/color]
          >
          > 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[/color]


          Comment

          • Oleg Tkachenko [MVP]

            #6
            Re: XmlNode.SelectN odes, order of nodes

            Vikram Vamshi wrote:[color=blue]
            > That is from the word interop documentation, do you think the same will hold
            > true for the .net 2.0 framework.[/color]

            Yes. But if your whole design depends on this feature you better sort
            selected nodes explicitly. XmlNode.SelectN odes 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

            Comment

            • Vikram Vamshi

              #7
              Re: XmlNode.SelectN odes, order of nodes

              Thanks!!!

              --
              Vikram Vamshi
              Database Engineer
              Eclipsys Corporation
              "Oleg Tkachenko [MVP]" <some@body.co m> wrote in message
              news:448FD306.8 030209@body.com ...[color=blue]
              > Vikram Vamshi wrote:[color=green]
              >> That is from the word interop documentation, do you think the same will
              >> hold true for the .net 2.0 framework.[/color]
              >
              > Yes. But if your whole design depends on this feature you better sort
              > selected nodes explicitly. XmlNode.SelectN odes 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[/color]


              Comment

              • Nagendra Kumar

                #8
                Re: XmlNode.SelectN odes, order of nodes


                Hi, Nice Replies those are worth ful..

                Please have a look at my blog

                The XML types are live in System.XML namespace 1. Import System.XML like using System.XML // now we are ready to use xml in .net 2. we h...





                *** Sent via Developersdex http://www.developersdex.com ***

                Comment

                • Nagendra Kumar

                  #9
                  Re: XmlNode.SelectN odes, order of nodes



                  Please Visit

                  The XML types are live in System.XML namespace 1. Import System.XML like using System.XML // now we are ready to use xml in .net 2. we h...



                  *** Sent via Developersdex http://www.developersdex.com ***

                  Comment

                  Working...