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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XLM and response.write (ASP)

Status
Not open for further replies.

Fursten

Programmer
Dec 27, 2000
403
PT
Hi,

In my ASP I (only) have this:

Response.Write &quot;<?xml version='1.0'?>&quot; & _
&quot;<booklist>&quot; & _
&quot;</booklist>&quot;

Despite I didnt had make: Response.ContentType = &quot;text/xml&quot;, when I run my ASP I get a XML document... this is strange because, by default, what I should be sending to the browser would be HTML! However, I don´t say I want to send XML but I get it! Why? Is something about the parser version? asp.dll? It seems that the XML tags are now recognized by the parser or something else... but they werent´...right?

This way, If I want to send an XML data island Putting &quot;<xml id=&quot;something&quot;> at the beggining and &quot;</xml> at the end of my response write I will get an error! Because it seems the browser was expecting to receive XML and not any other thing. I think that the logic was the browser to interpret that as HTML as I didn´t change the default contentType.

This way, if I want to send an XML data Island I will have to put <html> and </html> at the beggining and at the end of my response.write... I think I shouldnt need to do this, as I saying to the browser (by default) that everything that he wiil receive will be ... html.

By other words... Im confused! :) What was logic is not any more...

Sergio Oliveira
 
You are sending an XML document to the browser and it automatically displays it - this is a good way to see if you have a valid XML document. You want to embed XML in a data island from the server. The data island is just a special HTML tag so you have to send an HTML document to the browser. To do this create a variable in the server side script to hold your XML. Then in the HTML document create a data island and put your response.write there. For example:
Server script
strXML=&quot;<?xml version='1.0'?>&quot; & _
&quot;<booklist>&quot; & _
&quot;</booklist>&quot;

HTML document
<XML ID=&quot;myXMLDataIsland>
<% =strXML %>
</XML>

You now have a data island on you page.

Hope this helps.
 
Hi

I´m seeing your point, but my question would be like this:

Why I cant include on my response.write de <xml> tags, like this:

response.write &quot;<XML ID=&quot;myXMLDataIsland> & _
&quot;<% =strXML %> & _
&quot;</XML>&quot;

Note: In my ASP file I erase the <html> tags! So it doesn´t have any htlm tags on it. Just that response.write.

Do you see the point?

I say this way because I would like to understand response.write method. As far as I know the default value is &quot;text/html&quot; so, since I didn´t specify other value, what I should be sending to the browser would be html, got it? So this woul be a XMLdataIsland.

So, I have this:

<%@ language=&quot;vbscript&quot;%>

response.write &quot;<XML ID=&quot;myXMLDataIsland> & _
&quot;<% =strXML %> & _
&quot;</XML>&quot;
response.end

With this I get an error message, however, if I edit the result file and save it as HTML I would be able to open it without any problem.

other options:

1) html tags


<%@ language=&quot;vbscript&quot;%>

<html>
response.write &quot;<XML ID=&quot;myXMLDataIsland> & _
&quot;<% =strXML %> & _
&quot;</XML>&quot;
response.end
</html>

Result: html file with a XML data island on it.

2)

<%@ language=&quot;vbscript&quot;%>


response.write &quot;<?xml version='1.0'?>&quot; & _
&quot;<booklist>&quot; & _
&quot;</booklist>&quot;

response.end

Result: XML file, even despite I didn´t made Response.contentType = &quot;text/xml&quot; ?!?! I think this should be interpreted by the browser as HTML tags and not XML tags,as I let the default contentType as html.

Sergio Oliveira


 
Hi :)

Ok, I discovered what was going wrong... I was using MSXML2.5 parser, with its bugs! :)

I had upgraded to 3.0 SP1 and know everythings sounds logically.

thankx

Sergio Oliveira
 
I have a code as follow:
1. dim rs
2. dim doc
3. dim cn
4. dim searchField, withField
5.
6. ' Create Objects
7. set cn = server.CreateObject(&quot;ADODB.Connection&quot;)
8. set rs = server.CreateObject(&quot;ADODB.Recordset&quot;)
9. set doc = server.CreateObject(&quot;MSXML2.DomDocument&quot;)
10.
11. ' Open Connection
12. cn.Open &quot;CDLibrary;&quot;, &quot;sa&quot;, &quot;sqlserver2000&quot;
13.
14. ' Get required data
15. rs.Open &quot;select * from CD&quot;, cn, 0, 3
16.
17. ' Save Recordset to DOMDoc as XML
18. rs.Save doc, adPersistXML '1
19.
20.
21. ' Set Response property
22. Response.ContentType = &quot;text/xml&quot;
23.
24. ' Stylesheet for browser display
25. Response.Write &quot;<?xml:stylesheet type=&quot;&quot;text/xsl&quot;&quot; 26. href=&quot;&quot;CDList.xsl&quot;&quot;?>&quot; & vbcrlf

27. Response.Write doc.xml

At 18th row, why doc is empty after saving? Who can help me?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top