• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1469
  • Last Modified:

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
         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
  • 4
1 Solution
You could load the XML data into a disconnected recordset, then use the recordset sort function to do what you need.

I also found this:

Sorry for posting links, XML isn't my strongest discipline.
That last link is for ChiliKat. Not sure if that's applicable to you.
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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.

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

EE Admin

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now