Sort MSXML2.DomDocument

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 = "http://www.somesite.com/thexmlfile.xml

Set httpReq = Server.CreateObject("MSXML2.ServerXMLHTTP")
    httpReq.Open "GET",GetRequest, False
    httpReq.Send
         Set myXmlDoc =Server.CreateObject("MSXML2.DOMDocument")
    myXmlDoc.load(httpReq.responseBody)
    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      
                  Else
                        Response.Write(Quantity & " " & Country & "<br />")
                        QtyCount = Quantity + QtyCount
                  End if
            DupQtyRemove = Quantity
            Next
tarrigoAsked:
Who is Participating?
 
L00MCommented:
You could load the XML data into a disconnected recordset, then use the recordset sort function to do what you need.

http://support.microsoft.com/kb/272270
0
 
L00MCommented:
I also found this:
http://www.example-code.com/asp/xmlSort.asp

Sorry for posting links, XML isn't my strongest discipline.
0
 
L00MCommented:
That last link is for ChiliKat. Not sure if that's applicable to you.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
tarrigoAuthor Commented:
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.

0
 
L00MCommented:
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 :)
0
 
Computer101Commented:
Forced accept.

Computer101
EE Admin
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.