XMLHTTP and DocumentDom

Posted on 2007-08-11
Last Modified: 2008-01-09
I am trying to figure out why I am able to pull XML from a web site using MSXMLHTTP but when I load the responseText into the DocumentDom it doesn't accept the data. The funny thing is, if I pull the info from a static XML file it parses the data fine. This ultimately won't work for me though, because the url that I pic up the XML data from queries a web service with parameters so that the result set is different based on someones search  term. What is even more odd, is that when I do use the dynamic query in my code and also pass in that I want only  50 results, my code works fine.

Anybody have an thoughts on why that might be happening. Here is the code. I had to hide certain info in the url since it has password info, but this should help.


    Dim webServiceUrl, httpReq, node, myXmlDoc
' the url to get the data. It however does not work since I took out the site and password info
 thexmlquery =""

    Set httpReq = Server.CreateObject("MSXML2.XMLHTTP.6.0")
    httpReq.Open "GET",thexmlquery, False
         httpReq.SetRequestHeader "Content-type", "text/xml"
    Set myXmlDoc =Server.CreateObject("MSXML2.DOMDocument.6.0")
      theinfo = httpReq.responseXML.xml

   Set httpReq = Nothing
 'Get the necessary nodes to run the calculations.
 Set objNodeList = myXmlDoc.getElementsByTagName("Quantity")

  'Cycle through nodes and do calculations.
  QtyCount = 0
  For i = 0 TO (objNodeList.length -1)
    Set objNode = objNodeList.nextNode
  Quantity = objNode.text



Question by:tarrigo
    LVL 54

    Expert Comment

    I would first try fixing this by changing the code to ...

         theinfo = httpReq.xml

    Let me know how that works.


    Author Comment

    That didn't help unfortunately. Got the error below. The problem comes up because of the maxresults I ask for. One query was ok if I asked for 72 maxresults, but not 73. So that is what makes it so weird.  

    Microsoft VBScript runtime  error '800a01b6'

    Object doesn't support this property or method: 'xml'

    /soapy.asp, line 31

    LVL 58

    Expert Comment


          myXmlDoc.load httpReq.responseStream

    instead of


    Author Comment

    Unfortunately that didnt work. The interesting thing about this problem is that an XML result comes back every time. And it is a full result. What hangs up and is not working is the fact that when I go to get the Length of the nodeList sometimes it comes back as zero even though I can see that all the data was requested correctly using the XMLHTTP.6.0.

    So what I can't figure out is why I am able to get all the data, but can't sometimes get a proper .Length property on all my searches. If I could just get the NodeList length on 100 percent of the searches I would be set.
    LVL 58

    Expert Comment

    Does the DOM load successfully all the time? You should in fact check that

    bLoaded = myXmlDoc.load(httpReq.responseStream)


    bLoaded = myXmlDoc.loadxml(theinfo)

    and prceed only of bLoaded is True.

    Author Comment

    I actually found the problem. Believe it or not, I determined that anytime a search had these characters in one of the XML child nodes like:


    The DOMDocument would not parse the xml stream. If I took that out it would work fine. So that is definitely why it was not working.

    LVL 58

    Accepted Solution

    You could probably remove that before trying to load into the DOM...

    theinfo = Replace("&#x0;", "")
    bLoaded = myXmlDoc.loadxml(theinfo)

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
    The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    731 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

    18 Experts available now in Live!

    Get 1:1 Help Now