Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Client-side xml works but server-side doesn't

Status
Not open for further replies.

MarcusH

Programmer
May 3, 2001
22
GB
Hi,

I'm having a problem with getting code which works on the client side to work on the server in ASP.

This code works:

<script language=&quot;VBScript&quot;>

set xmldoc = CreateObject(&quot;Microsoft.XMLDOM&quot;)
xmldoc.async=False
xmldoc.Load (&quot;clientList.xml&quot;)

set element = xmldoc.getElementsByTagName(&quot;clients&quot;)

for each theItem in element
document.write theItem.getAttribute(&quot;lastName&quot;) &&quot;<br>&quot;
next

</script>

But this does not

<%
Response.buffer=true
Response.ContentType=&quot;text/xml&quot;

set xmldoc = Server.CreateObject(&quot;Microsoft.XMLDOM&quot;)
xmldoc.async=False
xmldoc.Load Server.MapPath(&quot;clientList.xml&quot;)

set element = xmldoc.getElementsByTagName(&quot;clients&quot;)

for each theItem in element
Response.write theItem.getAttribute(&quot;lastName&quot;) &&quot;<br>&quot;
next

%>

The error it comes up with is:

The XML page cannot be displayed
Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.


--------------------------------------------------------------------------------

Invalid at the top level of the document. Error processing resource ' Line 1, Position 1


Your help on this would be very much appreciated
Marcus
 
Set the content type to text/plain to see why it doesn't like your output. This will output it as plain text so you can see why it doesn't like it as xml

-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
For my next trick I will pull a hat out of a rabbit (if you think thats bad you should see how the pigeon feels...) :p
 
Thank you for pointing me in the right direction. I changed the content type to text/html and it worked.

Thanks
Marcus
 
The problem was most likely because it was expecting xml output in the response, but what you were outputting wasn't legal xml formatting which confused the parser. Since IE automatically runs any xml file it receives through it's own default XSL sheet for formatting (if it isn't already attached to an XSL sheet) the parser was attempting to validate and then apply the XSL sheet and failing.

-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
For my next trick I will pull a hat out of a rabbit (if you think thats bad you should see how the pigeon feels...) :p
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top