Displaying XML in a browser window

I been banging at this for a while and I’ve managed to find a solution that probably SHOULD work … but doesn’t.

I am trying to get IE to display some xml in the nice structered way it does - but using javascript. Certainly this works if the Content-type in the header is set to “text/xml” but i am trying to do this via javascript.

With out getting in to detail i am using ajax to download an xml response but I’d like to give the user an option (by clicking a button) to view the xml in a new browser window. So the idea is create new window then use document write to stick the xml in teh window. I thought i was made when i found document.open allows specifiying a mime type but it JUST DOESN’T work.

Here a code snippet.

var xmlstr = ‘<hello>world</hello>’;
function showbrowserwindow(s) {
hndl = window.open(‘’,‘xmlstr_window’,‘width=900,height=800’);
var newdoc = hndl.document.open(“text/xml”,“replace”); // set mime type
newdoc.write (s);
// alert (“Check Mime types” + hndl.document.mimeType + " and " + newdoc.mimeType);


<button onclick=“showbrowserwindow(xmlstr);”>

I quite baffled by this.
Any idea’s or alternatives welcome.
Thanks Guys
Ps. Newbie!! First post !

I am trying to get IE to display some xml in the nice structered way it does - but using javascript. Certainly this works if the Content-type in the header is set to “text/xml”

It does? How?

How about placing the content in an iframe, the content-type header of which is set to an XML mime type?

How does that allow xml to display? Maybe, I don’t understand what the op wants to display. Does he want this to display:


How I want it displayed is the same way that IE displays xml files.

Open an XML file in IE and it will display a structure view - i.e. indented and parsed, it and create little clickable plus/minus icons on the left column such that you can expand/contract each node. (this is what i want).

Open any xml file in IE (one with out an css, xslt or dtd associated).

IE will also will display XML messages from a server like this if the content type is “text/xml”. If the content type is not “text/xml” but instead is “text/html” IE interprets the xml tag names as mark up (style classes) and does not display the tag names at all.

The iframe idea is not a bad idea - but i was already doing this in lovely ajax so it doesn’t really fit.

THE current behaviour (in the code snippet) displays the text as if there content-type were “text/html” (despite my attempts to set the document mimetype.

Same problem with an iframe as with a new window - setting the content type is not possible (it appears to me) via javascript.

I could use the iframe as a target to download the xml - but as I said above this doesn’t fit my current ajax style mode of operation for a variety of reasons.

With out getting in to to much detail. THe page is like this.
Page loads and presents some form elements for generating a request. You click a button and ajax is used to send the request and get the xml response message which is captured (Via ajax). I want to have anohter button which can display this xml response ( i currently can pop it into a textarea but it would be really nice if i could open a new window and view it in a structed way (As described).

How about loading a skeleton page into the iframe with a meta tag like:

  <meta http-equiv="Content-Type" content="text/xml;charset=UTF-8">

Then targeting your AJAX output to an element within that page?

Yup - i tried that (Well in a new window - not an iframe). I even tried writting an <?xml … > header. Still no joy !!

Never did resolve this issue !