XML Query Question

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

    #1

    XML Query Question

    Hi,

    I have the following node within a xml document.

    <Results>
    <Result>
    <RecordID>1</RecordID>
    ...
    </Result>
    <Result>
    <RecordID>2</RecordID>
    ...
    </Result>
    <Result>
    <RecordID>1</RecordID>
    ...
    </Result>
    </Results>

    I am currently parsing this document using XMLDocument and looping through
    the Result nodes. I need to group the nodes by recordID. And compare to
    the records. How do I do this?

    Thanks


  • Mauricio Grimberg

    #2
    Re: XML Query Question

    xmlDocument.sel ectNodes("XPATH InstructionHere ") returns a filtered nodelist.
    As an example the XPATH expression "/Results/Result/RecordID=1" will give
    you a group like you are asking for.

    "george" <g@g.comwrote in message
    news:OHTKiO01GH A.4972@TK2MSFTN GP03.phx.gbl...
    Hi,
    >
    I have the following node within a xml document.
    >
    <Results>
    <Result>
    <RecordID>1</RecordID>
    ...
    </Result>
    <Result>
    <RecordID>2</RecordID>
    ...
    </Result>
    <Result>
    <RecordID>1</RecordID>
    ...
    </Result>
    </Results>
    >
    I am currently parsing this document using XMLDocument and looping through
    the Result nodes. I need to group the nodes by recordID. And compare to
    the records. How do I do this?
    >
    Thanks
    >

    Comment

    • John Saunders

      #3
      Re: XML Query Question

      "george" <g@g.comwrote in message
      news:OHTKiO01GH A.4972@TK2MSFTN GP03.phx.gbl...
      Hi,
      >
      I have the following node within a xml document.
      >
      <Results>
      <Result>
      <RecordID>1</RecordID>
      ...
      </Result>
      <Result>
      <RecordID>2</RecordID>
      ...
      </Result>
      <Result>
      <RecordID>1</RecordID>
      ...
      </Result>
      </Results>
      >
      I am currently parsing this document using XMLDocument and looping through
      the Result nodes. I need to group the nodes by recordID. And compare to
      the records. How do I do this?
      Have you considered using XSLT? It has an <xsl:sortinstru ction which you
      can use. Something like:

      <xsl:for-each select="Results/Result">
      <xsl:sort select=RecordID "/>
      <!-- Each Result node will be processed in order -->
      </xsl:for-each>

      John


      Comment

      Working...