XMLHTTP and DocumentDom

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 ="http://xmlsearch.thesite.com/xmlsearch.asmx/SearchInventory?User=username&Key=444444&Part=UDN2595A&Mfg=&DateCode=&DateCodeCompareType=0&MinQuantity=0&StockFlag=2&PricesOnly=false&PreferredVendorsOnly=false&Region=0&SearchType=0&MaxResults=250&PageNum=1&Sort="
   

    Set httpReq = Server.CreateObject("MSXML2.XMLHTTP.6.0")
    httpReq.Open "GET",thexmlquery, False
         httpReq.SetRequestHeader "Content-type", "text/xml"
      httpReq.Send
      
    Set myXmlDoc =Server.CreateObject("MSXML2.DOMDocument.6.0")
      'Response.write(httpReq.responseText)
      'Response.write(httpReq.responseText)
      theinfo = httpReq.responseXML.xml
      Response.Write(httpReq.GetAllResponseHeaders)
      myXmlDoc.loadxml(theinfo)

   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

      Response.write(Quantity)

      Next

%>
tarrigoAsked:
Who is Participating?
 
amit_gCommented:
You could probably remove that before trying to load into the DOM...

theinfo = Replace("&#x0;", "")
bLoaded = myXmlDoc.loadxml(theinfo)
0
 
b0lsc0ttIT ManagerCommented:
I would first try fixing this by changing the code to ...

     theinfo = httpReq.xml

Let me know how that works.

bol
0
 
tarrigoAuthor Commented:
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

0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
amit_gCommented:
Try

      myXmlDoc.load httpReq.responseStream

instead of

      myXmlDoc.loadxml(theinfo)
0
 
tarrigoAuthor Commented:
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.
0
 
amit_gCommented:
Does the DOM load successfully all the time? You should in fact check that

bLoaded = myXmlDoc.load(httpReq.responseStream)

or

bLoaded = myXmlDoc.loadxml(theinfo)

and prceed only of bLoaded is True.
0
 
tarrigoAuthor Commented:
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:

<price>&#x0;</price>

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.

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.