responseXML in Internet Explorer

W

wizard04frms

I'm having trouble figuring out what's going on with IE6's
Msxml2.XMLHTTP object. I have two feed addresses in this stripped down
version of my code below. Both work fine in Firefox (using the
XMLHttpRequest object), but only the thinkgeek one works in IE. In the
processFeed function, it shows the problem - the first alert shows 0
for the wikihow feed in IE, though it can still display the
responseText. Any insight?


//var feedAddr = "http://www.thinkgeek.com/thinkgeek.rss"; <<< works
fine in both
var feedAddr = "http://www.wikihow.com/feed.rss"; <<< only works in
FF

var url = "http://.../getXML.asp?url=" + feedAddr; <<< returns XML w/
content type text/xml
loadXMLDoc(url);

function loadXMLDoc(url)
{
var req;
if(window.XMLHttpRequest)
{
try { req = new XMLHttpRequest(); }
catch(e) { req = false; }
}
else if(window.ActiveXObject)
{
try { req = new ActiveXObject("Msxml2.XMLHTTP"); }
catch(e)
{
try { req = new ActiveXObject("Microsoft.XMLHTTP"); }
catch(e) { req = false; }
}
}
if(req)
{
req.onreadystatechange = function(){ processReqChange(req); };
req.open("GET", url, true);
req.send("");
}
else { XMLObjError(); }
}
function processReqChange(req)
{
if (req.readyState == 4)
{
if (req.status == 200) { processFeed(req); }
else { XMLReqError(); }
}
}
function processFeed(req)
{
var xmlDoc = req.responseXML;
alert(xmlDoc.childNodes.length); <<< shows 0 in IE for the wikihow
feed
alert(req.responseText);

//... do stuff
}
 
M

Martin Honnen

I'm having trouble figuring out what's going on with IE6's
Msxml2.XMLHTTP object. I have two feed addresses in this stripped down
version of my code below. Both work fine in Firefox (using the
XMLHttpRequest object), but only the thinkgeek one works in IE. In the
processFeed function, it shows the problem - the first alert shows 0
for the wikihow feed in IE, though it can still display the
responseText. Any insight?


//var feedAddr = "http://www.thinkgeek.com/thinkgeek.rss"; <<< works
fine in both
var feedAddr = "http://www.wikihow.com/feed.rss"; <<< only works in
FF

var url = "http://.../getXML.asp?url=" + feedAddr; <<< returns XML w/
content type text/xml
loadXMLDoc(url);

So in terms of the client side code you do not make a request to the URL
http://www.wikihow.com/feed.rss but rather to some different server that
then fetches the URL? Then look into that getXML.asp code and whether it
returns anything different.
Things to check on the client:

req.getAllResponseHeaders()
req.responseXML.parseError.errorCode
req.responseXML.parseError.reason

Show us the response headers you get. Or post the URL of that getXML.asp
script so that we can check what it returns.
 
W

wizard04frms

Martin said:
So in terms of the client side code you do not make a request to the URL
http://www.wikihow.com/feed.rss but rather to some different server that
then fetches the URL?

Yes, as far as I know, from the client side you can only make a request
to the same server as the page (that's the only way I could get it to
work anyway).
The asp script is only on my local server at the moment, so here's the
code:


function loadXML(byval xmlAddress)
dim xmlDoc

'Load the XML
set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.async = false
xmlDoc.setProperty "ServerHTTPRequest", true
on error resume next
xmlDoc.load(xmlAddress)
if err > 0 then
set loadXML = null
exit function
end if
set loadXML = xmlDoc
end function
dim x
dim address
dim content
address = request.QueryString("url")
if address <> "" then
set x = loadXML(address)
if isnull(x) or x.xml = "" then
response.Status = "404 Not Found"
response.End()
else
content = x.xml
end if
end if
response.ContentType = "text/xml"
response.Write(content)

Then look into that getXML.asp code and whether it
returns anything different.

The getXML.asp returns the same thing as going to the feed url
directly.
Things to check on the client:

req.getAllResponseHeaders()
req.responseXML.parseError.errorCode
req.responseXML.parseError.reason

Show us the response headers you get. Or post the URL of that getXML.asp
script so that we can check what it returns.

Here's what it returns in IE for the wikihow feed:


X-Powered-By: ASP.NET Content-Length: 6996 Content-Type: text/xml

-1072896760

An invalid character was found in text content.


I have no idea what this means...

Thanks for your help Martin.
 
M

Martin Honnen

set x = loadXML(address)
if isnull(x) or x.xml = "" then
response.Status = "404 Not Found"
response.End()
else
content = x.xml
end if
end if
response.ContentType = "text/xml"
response.Write(content)

Don't do that response.Write(content), instead simply do
x.save Response
if you want to send the loaded XML to the browser.
-1072896760

An invalid character was found in text content.

That means that MSXML in IE can't parse the XML your ASP returns as it
is not able to decode the bytes to characters, caused by changes in the
character encoding that probably occur due to your ASP page writing out
text in a certain code page that is different from the encoding the XML
doccument declares in its XML declaration. I hope my suggested change to
your ASP script fixes that problem.
 
W

wizard04frms

Martin said:
Don't do that response.Write(content), instead simply do
x.save Response
if you want to send the loaded XML to the browser.


That means that MSXML in IE can't parse the XML your ASP returns as it
is not able to decode the bytes to characters, caused by changes in the
character encoding that probably occur due to your ASP page writing out
text in a certain code page that is different from the encoding the XML
doccument declares in its XML declaration. I hope my suggested change to
your ASP script fixes that problem.

Thanks for the explanation. That change didn't have any effect,
however.
 
M

Martin Honnen

That change didn't have any effect,
however.

It is an ASP problem not a JavaScript problem. One way with MSXML and
ASP to grab another URL and send it to the client unchanged could be
alike (very rough outline, no error checking)

Set HttpRequest = CreateObject("Msxml2.ServerXMLHTTP.3.0")
HttpRequest.open "GET", Request.QueryString("url"), False
HttpRequest.send

If HttpRequest.status = 200 Then
Response.ContentType = HttpRequest.getResponseHeader("Content-Type")
Response.BinaryWrite HttpRequest.responseBody
End

I hope those lines help, if not consider asking in a Microsoft group on
ASP or XML (e.g. microsoft.public.xml).

Or use J(ava)Script in ASP :), then we could deal with it here without
getting off topic.
 
W

wizard04frms

Your first suggestion DID work! I just had to close IE and open it
again 'cause it wasn't refreshing - sheesh!

Thanks!
 

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,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top