?
Solved

XMLHTTP and DocumentDom

Posted on 2007-08-11
7
Medium Priority
?
270 Views
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 ="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

%>
0
Comment
Question by:tarrigo
  • 3
  • 3
7 Comments
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 19677907
I would first try fixing this by changing the code to ...

     theinfo = httpReq.xml

Let me know how that works.

bol
0
 

Author Comment

by:tarrigo
ID: 19677925
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
 
LVL 58

Expert Comment

by:amit_g
ID: 19686437
Try

      myXmlDoc.load httpReq.responseStream

instead of

      myXmlDoc.loadxml(theinfo)
0
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.

 

Author Comment

by:tarrigo
ID: 19687494
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
 
LVL 58

Expert Comment

by:amit_g
ID: 19687690
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
 

Author Comment

by:tarrigo
ID: 19687894
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
 
LVL 58

Accepted Solution

by:
amit_g earned 2000 total points
ID: 19688027
You could probably remove that before trying to load into the DOM...

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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
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. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

840 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