Sort MSXML2.DomDocument

Posted on 2007-08-10
Last Modified: 2012-08-13
I am wondering if an XMLDOM result can be sorted before it is iterated through. My code looks like this, but before iterate and display certain nodes, I want to sort the quantity.

Dim GetRequest
GetRequest = "

Set httpReq = Server.CreateObject("MSXML2.ServerXMLHTTP")
    httpReq.Open "GET",GetRequest, False
         Set myXmlDoc =Server.CreateObject("MSXML2.DOMDocument")
    Set httpReq = Nothing
      'Get the necessary nodes to run the calculations.
      Set objNodeList = myXmlDoc.getElementsByTagName("Quantity")
      Set objNodeList2 = myXmlDoc.getElementsByTagName("CountryName")
            'Cycle through nodes and do calculations.
            QtyCount = 0
            For i = 0 TO (objNodeList.length -1)
              Set objNode = objNodeList.nextNode
              Set objNode2 = objNodeList2.nextNode
            Quantity = objNode.text
             Country = objNode2.text
            'If DupQtyRemove = Quantity OR Country = "China" Then      
                        Response.Write(Quantity & " " & Country & "<br />")
                        QtyCount = Quantity + QtyCount
                  End if
            DupQtyRemove = Quantity
Question by:tarrigo
    LVL 11

    Accepted Solution

    You could load the XML data into a disconnected recordset, then use the recordset sort function to do what you need.
    LVL 11

    Expert Comment

    I also found this:

    Sorry for posting links, XML isn't my strongest discipline.
    LVL 11

    Expert Comment

    That last link is for ChiliKat. Not sure if that's applicable to you.

    Author Comment

    These are good solutions that I might try. Chilkat is a great product, but it does not handle all XML results. I have contacted them numerous times about it and they pretty much gave up on trying to modify their product. It does not handle diffgram or Dataset being in the XML result set on a HTTP GET. Otherwise I would have great things to say about the product.

    They accused me of not installing it, but I showed them many times that if I commented those lines out that the XML file iterated great using their component.

    Anyways, I decided to go with the MSXMLDOM and it is crucial I sort the result because I have to iterate through the result and make sure that any duplicate quanitities do not get added twice. We query an electronic parts database and through a web service and duplicate quantities tend to mean it is the same part trying to be sold by multiple brokers.

    LVL 11

    Expert Comment

    It sounds like a disconnected recordset would work great for you then.
    Also, and keep in mind, I'm not the XML expert, but you can use an XSL document to consume the XML and produce your desired results.
    I'm just old fashioned though, I'd use the recordset :)
    LVL 1

    Expert Comment

    Forced accept.

    EE Admin

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
    Introduction In my previous article ( I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now