views:

130

answers:

2

I have a IXMLDOMDocument2 type document. I would like to see the xml for this document. How can I turn it in to a string so I can view it? I am using javascript. The .text properity is just "".

A: 

Let say d is your variable for the xml Document

var strXML = d.xml; //IE

var strXML = (new XMLSerializer()).serializeToString(d); //NON-IE
jerjer
+1  A: 

This should do it:

//Convert XML DOM to a string
//for IE 
if (window.ActiveXObject) {
    var str = myObj.xml;
    alert(str);
 }
// code for Mozilla, Firefox, Opera, etc.
else {
   var str = (new XMLSerializer()).serializeToString(myObj);
   alert(str);
}

assuming myObj is your XML variable.

karim79
+1 for cross browser solution.
Martijn Laarman