responseXML.documentElement.childNodes Error

F

fniles

In my ASP page I open a file on the intranet and reads in as XML stream.
I can open the file fine, but when I do "For Each TopicChildNode In
xmlHttp.responseXML.documentElement.childNodes" I got the error "HTTP 500
Internal Server error" "The website cannot display the page. Most likely
causes:
The website is under maintenance
The website has a programming error"

If I open and reads a file from say
"http://local.yahooapis.com/MapsServ...&street=701+First+Ave&city=Sunnyvale&state=CA"
I do NOT get any error.

What causes the error in this case and how can I fix it ?
Thank you.

Set xmlHTTP = Server.CreateObject("Msxml2.serverXMLHTTP.3.0")
xmlHTTP.open "GET","http://myIntranetSite/thisweek?OPTION",false
xmlHTTP.send
For Each TopicChildNode In
mlHttp.responseXML.documentElement.childNodes -> ERROR here
:
next
 
D

Daniel Crichton

fniles wrote on Mon, 16 Mar 2009 10:38:35 -0500:
In my ASP page I open a file on the intranet and reads in as XML
stream.
I can open the file fine, but when I do "For Each TopicChildNode In
xmlHttp.responseXML.documentElement.childNodes" I got the error "HTTP
500 Internal Server error" "The website cannot display the page. Most
likely causes:
The website is under maintenance
The website has a programming error"
If I open and reads a file from say
"http://local.yahooapis.com/MapsService/V1/geocode?appid=YD-9G7bey8_
JXxQP6rxl.fBFGgCdNjoDMACQA--&street=701+First+Ave&city=Sunnyvale&state=
CA" I do NOT get any error.
What causes the error in this case and how can I fix it ?
Thank you.
Set xmlHTTP = Server.CreateObject("Msxml2.serverXMLHTTP.3.0")
xmlHTTP.open "GET","http://myIntranetSite/thisweek?OPTION",false
xmlHTTP.send
For Each TopicChildNode In
lHttp.responseXML.documentElement.childNodes -> ERROR here :
next

If the URL being requested does not return XML then responseXML will be
empty so again you'll get an error.

If you turn off "Show Friendly Error Messages" in IE, what does the error
then show? Often the real error message is hidden by IE unless you do this,
seeing the raw error might give you an idea of what the problem is.

Also, if your code above is a copy-paste then you appear to be missing an x
in "In mlHttp" which should be "In xmlHttp".
 
F

fniles

Thank you.
Will it make any difference if the XML is generated by SAP using web
services ?

I will ask the client to turn off "Show Friendly Error Messages" in IE and
see what he gets.
Also, if your code above is a copy-paste then you appear to be missing an
x in "In mlHttp" which should be "In xmlHttp".
Yes, it's a typo when I posted the question on the forum. In my ASP page, it
does say xmlHTTP.

Thank you.
 
D

Daniel Crichton

So long as it's valid XML and the correct MIME header is sent it should
work. But if the XML is invalid then it's not going to work.

Dan

fniles wrote on Mon, 16 Mar 2009 12:19:13 -0500:
Thank you.
Will it make any difference if the XML is generated by SAP using web
services ?
I will ask the client to turn off "Show Friendly Error Messages" in IE
and see what he gets.
Yes, it's a typo when I posted the question on the forum. In my ASP
page, it does say xmlHTTP.
 
M

Martin Honnen

fniles said:
Will it make any difference if the XML is generated by SAP using web
services ?

They need to set the HTTP response Content-Type header as
Content-Type: application/xml
or
Content-Type: text/xml
to have MSXML try to populate responseXML.
 
F

fniles

Thank you.

Did you mean the file needs to have Content-Type: application/xml or
Content-Type: text/xml ?

When I GET
http://local.yahooapis.com/MapsServ...&street=701+First+Ave&city=Sunnyvale&state=CA,
it works fine.
The file looks like the following: ( I do not see Content-Type:
application/xml or Content-Type: text/xml in the file, but responseXML
works)
<?xml version="1.0" ?>
- <ResultSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:yahoo:maps" xsi:schemaLocation="urn:yahoo:maps
http://api.local.yahoo.com/MapsService/V1/GeocodeResponse.xsd">
- <Result precision="address">
<Latitude>37.416397</Latitude>
::
</Result>
</ResultSet>

The intranet file that does not work has the following heading:
<?xml version="1.0" encoding="iso-8859-1"?>
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<TABLE>
:
</TABLE>
</asx:values>
</asx:abap>
 
F

fniles

Thank you.

What do you mean by MIME header is sent ?

When I GET
http://local.yahooapis.com/MapsServ...&street=701+First+Ave&city=Sunnyvale&state=CA,
it works fine.
The file looks like the following:
<?xml version="1.0" ?>
- <ResultSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:yahoo:maps" xsi:schemaLocation="urn:yahoo:maps
http://api.local.yahoo.com/MapsService/V1/GeocodeResponse.xsd">
- <Result precision="address">
<Latitude>37.416397</Latitude>
::
</Result>
</ResultSet>

The intranet file that does not work has the following heading:
<?xml version="1.0" encoding="iso-8859-1"?>
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<TABLE>
:
</TABLE>
</asx:values>
</asx:abap>
 
D

Daniel Crichton

That's the response body. You need to look at the headers too. You can do
this using a HTTP trace tool like Fiddler2, or by connecting to the server
and requesting the page via a telnet type application.

For the URL you gave I used Fiddler2, here's the output of the response headers:


HTTP/1.1 200 OK
Date: Tue, 17 Mar 2009 11:40:40 GMT
P3P: policyref="http://info.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM
DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND
PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE LOC GOV"
Cache-Control: private
Connection: close
Content-Type: text/xml; charset=utf-8
Content-Length: 516


As you can see the Content-Type header here is text/xml, so it will be
parsed by the ServerXMLHTTP object automatically. Try the same with your
intranet request. If you don't want to use Fiddler2 (I can highly recommend
it though) you can do it using a telnet type application easily. For
instance, in Windows open a command prompt and type

telnet intranet 80

you'll then have a flashing cursor, type

GET /thisweek?OPTION HTTP/1.1
Host: intranet


and press enter twice at the end (you need to send a blank line, then
another blank line to finish the request). If the server doesn't need any
other HTTP request headers (for instant user-agent information, cookies,
etc) then it should return the xml. You need to look at the first part of
the response before the XML to see the headers. If Content-Type is missing,
or is not set to an xml MIME type, then the ServerXMLHTTP object will not
automatically parse it and you'll get an error if you try to use the
responseXML.xml object.

You can take the output though and use a DOM object to load it and parse it.
eg.

Set xmlHTTP = Server.CreateObject("Msxml2.serverXMLHTTP.3.0")
xmlHTTP.open "GET","http://myIntranetSite/thisweek?OPTION",false
xmlHTTP.send

mResponseXML = xmlHTTP.responseText

If mResponseXML = "" Then
'no response, handle it here
Else
Set xml = Server.CreateObject("MSXML2.DOMDocument60")
xml.async = False
xml.validateOnParse = True

xml.LoadXML mResponseXML

If xml.parseError.errorCode <> 0 Then
'error, not valid XML, handle here
Else
For Each TopicChildNode In xml.documentElement.childNodes
...
Next
End If
End If


(code above is untested, but the basics were copied from an application I
have running on a daily basis processing XML data from a remote site).

What the above does is to get the XML from the responseText property (if the
XML is not valid or automatically parsed then responseXML will be empty, but
responseText will not be), then load it into a DOMDocument object with parse
checking turned on, and only if that can be loaded as XML then will the code
go into looping through the childnodes.


Dan

fniles wrote on Mon, 16 Mar 2009 15:15:54 -0500:
Thank you.
Did you mean the file needs to have Content-Type: application/xml or Content-Type:
text/xml ?
When I GET http://local.yahooapis.com/MapsService/V1/geocode?appid=YD-9G7bey8_
JXxQP6rxl.fBFGgCdNjoDMACQA--&street=701+First+Ave&city=Sunnyvale&state=
CA, it works fine.
The file looks like the following: ( I do not see Content-Type:
application/xml or Content-Type: text/xml in the file, but responseXML
works)
<?xml version="1.0" ?>
- <ResultSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:yahoo:maps" xsi:schemaLocation="urn:yahoo:maps http://api.local.yahoo.com/MapsService/V1/GeocodeResponse.xsd">
- <Result precision="address">
<Latitude>37.416397</Latitude>
::
</Result>
</ResultSet>
The intranet file that does not work has the following heading:
<?xml version="1.0" encoding="iso-8859-1"?>
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<TABLE>
:
</TABLE>
</asx:values>
</asx:abap>


Martin Honnen said:
fniles wrote:
They need to set the HTTP response Content-Type header as
Content-Type: application/xml or
Content-Type: text/xml to have MSXML try to populate responseXML.
 
F

fniles

Thank you so much for your help.

I will try your suggestion with the DOM object.

How can I telnet
http://local.yahooapis.com/MapsServ...&street=701+First+Ave&city=Sunnyvale&state=CA ?
Do I need to surround the URL with " ?
What port shall I use ?

Daniel Crichton said:
That's the response body. You need to look at the headers too. You can do
this using a HTTP trace tool like Fiddler2, or by connecting to the server
and requesting the page via a telnet type application.

For the URL you gave I used Fiddler2, here's the output of the response
headers:


HTTP/1.1 200 OK
Date: Tue, 17 Mar 2009 11:40:40 GMT
P3P: policyref="http://info.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR
ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi
IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE LOC GOV"
Cache-Control: private
Connection: close
Content-Type: text/xml; charset=utf-8
Content-Length: 516


As you can see the Content-Type header here is text/xml, so it will be
parsed by the ServerXMLHTTP object automatically. Try the same with your
intranet request. If you don't want to use Fiddler2 (I can highly
recommend it though) you can do it using a telnet type application easily.
For instance, in Windows open a command prompt and type

telnet intranet 80

you'll then have a flashing cursor, type

GET /thisweek?OPTION HTTP/1.1
Host: intranet


and press enter twice at the end (you need to send a blank line, then
another blank line to finish the request). If the server doesn't need any
other HTTP request headers (for instant user-agent information, cookies,
etc) then it should return the xml. You need to look at the first part of
the response before the XML to see the headers. If Content-Type is
missing, or is not set to an xml MIME type, then the ServerXMLHTTP object
will not automatically parse it and you'll get an error if you try to use
the responseXML.xml object.

You can take the output though and use a DOM object to load it and parse
it. eg.

Set xmlHTTP = Server.CreateObject("Msxml2.serverXMLHTTP.3.0")
xmlHTTP.open "GET","http://myIntranetSite/thisweek?OPTION",false
xmlHTTP.send

mResponseXML = xmlHTTP.responseText

If mResponseXML = "" Then
'no response, handle it here
Else
Set xml = Server.CreateObject("MSXML2.DOMDocument60")
xml.async = False
xml.validateOnParse = True

xml.LoadXML mResponseXML

If xml.parseError.errorCode <> 0 Then
'error, not valid XML, handle here
Else
For Each TopicChildNode In xml.documentElement.childNodes
...
Next
End If
End If


(code above is untested, but the basics were copied from an application I
have running on a daily basis processing XML data from a remote site).

What the above does is to get the XML from the responseText property (if
the XML is not valid or automatically parsed then responseXML will be
empty, but responseText will not be), then load it into a DOMDocument
object with parse checking turned on, and only if that can be loaded as
XML then will the code go into looping through the childnodes.


Dan

fniles wrote on Mon, 16 Mar 2009 15:15:54 -0500:
Thank you.
Did you mean the file needs to have Content-Type: application/xml or
Content-Type: text/xml ?
When I GET
http://local.yahooapis.com/MapsService/V1/geocode?appid=YD-9G7bey8_
JXxQP6rxl.fBFGgCdNjoDMACQA--&street=701+First+Ave&city=Sunnyvale&state=
CA, it works fine.
The file looks like the following: ( I do not see Content-Type:
application/xml or Content-Type: text/xml in the file, but responseXML
works)
<?xml version="1.0" ?>
- <ResultSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:yahoo:maps" xsi:schemaLocation="urn:yahoo:maps
http://api.local.yahoo.com/MapsService/V1/GeocodeResponse.xsd">
- <Result precision="address">
<Latitude>37.416397</Latitude>
::
</Result>
</ResultSet>
The intranet file that does not work has the following heading:
<?xml version="1.0" encoding="iso-8859-1"?>
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<TABLE>
:
</TABLE>
</asx:values>
</asx:abap>


Martin Honnen said:
fniles wrote:
Will it make any difference if the XML is generated by SAP using web
services ?
They need to set the HTTP response Content-Type header as
Content-Type: application/xml or
Content-Type: text/xml to have MSXML try to populate responseXML.
 
D

Daniel Crichton

fniles wrote on Tue, 17 Mar 2009 12:03:26 -0500:
Thank you so much for your help.
I will try your suggestion with the DOM object.
How can I telnet http://local.yahooapis.com/MapsService/V1/geocode?appid=YD-9G7bey8_
JXxQP6rxl.fBFGgCdNjoDMACQA--&street=701+First+Ave&city=Sunnyvale&state=
CA ?
Do I need to surround the URL with " ?
What port shall I use ?

You would do

telnet local.yahooapis.com 80

then type

GET
/MapsService/V1/geocode?appid=YD-9G7bey8_JXxQP6rxl.fBFGgCdNjoDMACQA--&street=701+First+Ave&city=Sunnyvale&state=CA
HTTP/1.1
Host: local.yahooapis.com


(note that the GET and up to and including the HTTP/1.1 needs to all be on a
single line). It's really much easier to use Fiddler2 :)


Dan



Daniel Crichton said:
That's the response body. You need to look at the headers too. You
can do this using a HTTP trace tool like Fiddler2, or by connecting
to the server and requesting the page via a telnet type application.
For the URL you gave I used Fiddler2, here's the output of the
response headers:
HTTP/1.1 200 OK
Date: Tue, 17 Mar 2009 11:40:40 GMT
P3P: policyref="http://info.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR
CUR
ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi
PUBi
IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE LOC GOV"
Cache-Control: private
Connection: close
Content-Type: text/xml; charset=utf-8
Content-Length: 516
As you can see the Content-Type header here is text/xml, so it will
be parsed by the ServerXMLHTTP object automatically. Try the same
with your intranet request. If you don't want to use Fiddler2 (I can
highly recommend it though) you can do it using a telnet type
application easily.
For instance, in Windows open a command prompt and type
telnet intranet 80
you'll then have a flashing cursor, type
GET /thisweek?OPTION HTTP/1.1
Host: intranet
and press enter twice at the end (you need to send a blank line, then
another blank line to finish the request). If the server doesn't need
any other HTTP request headers (for instant user-agent information,
cookies, etc) then it should return the xml. You need to look at the
first part of the response before the XML to see the headers. If
Content-Type is missing, or is not set to an xml MIME type, then the
ServerXMLHTTP object will not automatically parse it and you'll get
an error if you try to use the responseXML.xml object.
You can take the output though and use a DOM object to load it and
parse it. eg.
Set xmlHTTP = Server.CreateObject("Msxml2.serverXMLHTTP.3.0")
xmlHTTP.open "GET","http://myIntranetSite/thisweek?OPTION",false
xmlHTTP.send
mResponseXML = xmlHTTP.responseText
If mResponseXML = "" Then 'no response, handle it here
Else
Set xml = Server.CreateObject("MSXML2.DOMDocument60")
xml.async = False xml.validateOnParse = True
xml.LoadXML mResponseXML
If xml.parseError.errorCode <> 0 Then 'error, not valid
XML, handle here
Else
For Each TopicChildNode In xml.documentElement.childNodes
...
Next
End If
End If
(code above is untested, but the basics were copied from an
application I have running on a daily basis processing XML data from
a remote site).
What the above does is to get the XML from the responseText property
(if the XML is not valid or automatically parsed then responseXML
will be empty, but responseText will not be), then load it into a
DOMDocument object with parse checking turned on, and only if that
can be loaded as
XML then will the code go into looping through the childnodes.
Dan
fniles wrote on Mon, 16 Mar 2009 15:15:54 -0500:

 
F

fniles

Thank you for your help !

Daniel Crichton said:
fniles wrote on Tue, 17 Mar 2009 12:03:26 -0500:
Thank you so much for your help.
I will try your suggestion with the DOM object.
How can I telnet
http://local.yahooapis.com/MapsService/V1/geocode?appid=YD-9G7bey8_
JXxQP6rxl.fBFGgCdNjoDMACQA--&street=701+First+Ave&city=Sunnyvale&state=
CA ?
Do I need to surround the URL with " ?
What port shall I use ?

You would do

telnet local.yahooapis.com 80

then type

GET
/MapsService/V1/geocode?appid=YD-9G7bey8_JXxQP6rxl.fBFGgCdNjoDMACQA--&street=701+First+Ave&city=Sunnyvale&state=CA
HTTP/1.1
Host: local.yahooapis.com


(note that the GET and up to and including the HTTP/1.1 needs to all be on
a single line). It's really much easier to use Fiddler2 :)


Dan



Daniel Crichton said:
That's the response body. You need to look at the headers too. You
can do this using a HTTP trace tool like Fiddler2, or by connecting
to the server and requesting the page via a telnet type application.
For the URL you gave I used Fiddler2, here's the output of the
response headers:
HTTP/1.1 200 OK
Date: Tue, 17 Mar 2009 11:40:40 GMT
P3P: policyref="http://info.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR
CUR
ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi
PUBi
IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE LOC GOV"
Cache-Control: private
Connection: close
Content-Type: text/xml; charset=utf-8
Content-Length: 516
As you can see the Content-Type header here is text/xml, so it will
be parsed by the ServerXMLHTTP object automatically. Try the same
with your intranet request. If you don't want to use Fiddler2 (I can
highly recommend it though) you can do it using a telnet type
application easily.
For instance, in Windows open a command prompt and type
telnet intranet 80
you'll then have a flashing cursor, type
GET /thisweek?OPTION HTTP/1.1
Host: intranet
and press enter twice at the end (you need to send a blank line, then
another blank line to finish the request). If the server doesn't need
any other HTTP request headers (for instant user-agent information,
cookies, etc) then it should return the xml. You need to look at the
first part of the response before the XML to see the headers. If
Content-Type is missing, or is not set to an xml MIME type, then the
ServerXMLHTTP object will not automatically parse it and you'll get
an error if you try to use the responseXML.xml object.
You can take the output though and use a DOM object to load it and
parse it. eg.
Set xmlHTTP = Server.CreateObject("Msxml2.serverXMLHTTP.3.0")
xmlHTTP.open "GET","http://myIntranetSite/thisweek?OPTION",false
xmlHTTP.send
mResponseXML = xmlHTTP.responseText
If mResponseXML = "" Then 'no response, handle it here
Else
Set xml = Server.CreateObject("MSXML2.DOMDocument60")
xml.async = False xml.validateOnParse = True
xml.LoadXML mResponseXML
If xml.parseError.errorCode <> 0 Then 'error, not valid
XML, handle here
Else
For Each TopicChildNode In xml.documentElement.childNodes
...
Next
End If
End If
(code above is untested, but the basics were copied from an
application I have running on a daily basis processing XML data from
a remote site).
What the above does is to get the XML from the responseText property
(if the XML is not valid or automatically parsed then responseXML
will be empty, but responseText will not be), then load it into a
DOMDocument object with parse checking turned on, and only if that
can be loaded as
XML then will the code go into looping through the childnodes.
Dan
fniles wrote on Mon, 16 Mar 2009 15:15:54 -0500:
Thank you.
Did you mean the file needs to have Content-Type: application/xml or
Content-Type: text/xml ?
When I GET
http://local.yahooapis.com/MapsService/V1/geocode?appid=YD-9G7bey8_
JXxQP6rxl.fBFGgCdNjoDMACQA--&street=701+First+Ave&city=Sunnyvale&
state=
CA, it works fine.
The file looks like the following: ( I do not see Content-Type:
application/xml or Content-Type: text/xml in the file, but
responseXML works)
<?xml version="1.0" ?>
- <ResultSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:yahoo:maps" xsi:schemaLocation="urn:yahoo:maps
http://api.local.yahoo.com/MapsService/V1/GeocodeResponse.xsd">
- <Result precision="address">
<Latitude>37.416397</Latitude>
::
</Result>
</ResultSet>
The intranet file that does not work has the following heading:
<?xml version="1.0" encoding="iso-8859-1"?>
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<TABLE>
:
</TABLE>
</asx:values>
</asx:abap>

fniles wrote:
Will it make any difference if the XML is generated by SAP using
web services ?
They need to set the HTTP response Content-Type header as
Content-Type: application/xml or
Content-Type: text/xml to have MSXML try to populate responseXML.
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top