XML parsing using ASP

V

VK

Dear All:

I have an issue trying to parse response from xml document, for that
matter I don't receive back response.

I am trying to integrate UPS e-commerce online tool into our web site,
this tool calcuates the rates and services and returns back all the
different shipping rates.

Below is the code trying to display the return response.

==============
Set xml = Server.CreateObject("Microsoft.XMLHTTP")
xml.Open "POST", "https://wwwcie.ups.com/ups.app/xml/rate", False
xml.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xml.Send xmltext
Response.Write xml.responseText
Dim xmldom
Set xmldom = Server.CreateObject("Microsoft.XMLDOM")
xmldom.async = false
xmldom.loadxml(xml.responseText)

(xmltext - has the XML string to send )

When I try to set
Set root = xmldom.documentElement

and try to display the child nodes - it comes back with error message.

Any help would be appreciated.

Many thanks.
 
B

Bob Barrows [MVP]

VK said:
Dear All:

I have an issue trying to parse response from xml document, for that
matter I don't receive back response.

I am trying to integrate UPS e-commerce online tool into our web site,
this tool calcuates the rates and services and returns back all the
different shipping rates.

Below is the code trying to display the return response.

==============
Set xml = Server.CreateObject("Microsoft.XMLHTTP")

You should use "Microsoft.ServerXMLHTTP" in server-side code.I would also
suggest using "msxm2" instead of "Microsoft" to avoid version problems.
xml.Open "POST", "https://wwwcie.ups.com/ups.app/xml/rate", False
xml.setRequestHeader "Content-Type",
"application/x-www-form-urlencoded" xml.Send xmltext
Response.Write xml.responseText
Dim xmldom
Set xmldom = Server.CreateObject("Microsoft.XMLDOM")
xmldom.async = false
xmldom.loadxml(xml.responseText)

(xmltext - has the XML string to send )

When I try to set
Set root = xmldom.documentElement

and try to display the child nodes - it comes back with error message.

????
Are we supposed to look up your error message in our crystal ball?

Bob Barrows
 
V

VK

Here is the code:
set node = xmldom.documentElement
For Each child In node.childNodes
response.write child.Nodename & ": (" & child.Text & ")" & "<BR>"
next

Error message:
Microsoft VBScript runtime error '800a01a8'

Object required
 
B

Bob Barrows [MVP]

VK said:
Here is the code:
set node = xmldom.documentElement
For Each child In node.childNodes
response.write child.Nodename & ": (" & child.Text & ")" & "<BR>"
next

Error message:
Microsoft VBScript runtime error '800a01a8'

Object required
Instead of

xmldom.loadxml(xml.responseText)

do this:

bStatus = xmldom.loadxml(xml.responseText)
if not bStatus then
Set xPE = xmldom.parseError
strMessage = "errorCode = " & xPE.errorCode & "<BR>"
strMessage = strMessage & "reason = " & xPE.reason & "<BR>"
strMessage = strMessage & "Line = " & xPE.Line & "<BR>"
strMessage = strMessage & "linepos = " & xPE.linepos & "<BR>"
strMessage = strMessage & "filepos = " & xPE.filepos & "<BR>"
strMessage = strMessage & "srcText = " & xPE.srcText & "<BR>"
Response.Write strMessage
Response.End
end if

Alternatively, there IS a ResponseXML property which can be used:

Set xmldom=xml.responseXML

Note: If the response was generated by an Active Server Pages (ASP) page and
the Multipurpose Internet Mail Extension (MIME) type was not correctly set
to "text/xml" using the ASP method Response.ContentType, responseXML will be
empty.

Bob Barrows
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top