Muneem Habib
Muneem Habib

Reputation: 1094

How to read xml file in javascript

I have made a dialog which gets path of xml file and read content of xml file in a string. i have a variable called output which stires all contents of XML file. Now output is a string which contains all xml file contents. Now i want to parse this output

my code for parsing this is as follows:

output = e.target.result;
            console.log("file path"); 
            console.log(output);
            /*var xmlDoc=loadXMLDoc(output);
            console.log("XML DOC");
            console.log(xmlDoc);
            */
              myXML= document.all(output).XMLDocument
              console.log(myXML);

i am getting error of XMLDocument undefined. How should i parse this xmlstring?

Upvotes: 0

Views: 1793

Answers (1)

RealityDysfunction
RealityDysfunction

Reputation: 2639

You can use xmlSerializer.

var xmlText = new XMLSerializer().serializeToString(xml);
var xmlTextNode = document.createTextNode(xmlText);
someDOMobject.appendChild(xmlTextNode);

More examples: Convert XML to String and append to page

Upvotes: 1

Related Questions