How to get innerXml or outer XML in JavaScript and FireFox

When using IE, the following works are done -

 alert("XML Root IE: " + xmlDoc.documentElement.tagName); // ok
 alert("Xml: " + xmlDoc.documentElement.xml);             // ok

      

but for FireFox the functions xml, innerxml, outerxml are all undefined.

   alert("tagName: " + xmlDoc.documentElement.tagName);  // ok
   alert("Xml Content: " + xmlDoc.documentElement.xml);  // undefined
   alert("Xml innerxml: " + xmlDoc.documentElement.innerxml);  // undefined
   alert("Xml outerxml: " + xmlDoc.documentElement.outerxml);  // undefined

      

How do I get the actual XML on FireFox? (I know I read the XML correctly because "documentElement.tagName" correctly returns IE and FF)

Thank,

Atar

EDIT: Here is the relevant FF code:

    var xmlDoc;

function fLoadXml() {
  // alert("fLoadXml()");
  if (window.ActiveXObject) { // IE
    fLoadXmlIE()
  } else if (document.implementation && document.implementation.createDocument) { // FF
    fLoadXmlFF()
  }
}

function fLoadXmlFF() {
   // alert("fLoadXmlFF()");
   xmlDoc = document.implementation.createDocument("","",null) ;
   xmlDoc.async = false;
   xmlDoc.onload = fReadXmlFF;
   var loaded = xmlDoc.load("myFile.xml");
   alert("loaded: " + loaded);
}

function fReadXmlFF() {
   alert("fReadXmlFF()");
   alert("tagName: " + xmlDoc.documentElement.tagName);
   alert("Xml Content: " + xmlDoc.documentElement.xml);  // undefined
   alert("Xml innerxml: " + xmlDoc.documentElement.innerxml);  // undefined
   alert("Xml outerxml: " + xmlDoc.documentElement.outerxml);  // undefined

}

      

+3


source to share


2 answers


Found it - http://www.hiteshagrawal.com/javascript/convert-xml-document-to-string-in-javascript

Decision:



function fReadXmlFF() {
   alert("tagName: " + xmlDoc.documentElement.tagName);  // ok
   strXml = (new XMLSerializer()).serializeToString(xmlDoc); // ok
   . . . 

      

+7


source


xml is IE only property, try something else like ChildNodes and NodeValue check here: http://www.w3schools.com/dom/dom_document.asp



+1


source







All Articles