Read entire xml file

S

Sunny

Hi,
Can someone tell me how to get the content of entire xml file in
Firefox?
I am using this code to load the xml file.
if (document.implementation && document.implementation.createDocument)
{
xmlDoc = document.implementation.createDocument("","",null);
xmlDoc.async="false";
var isLoaded = xmlDoc.load("allcounties_3.xml");
if (isLoaded == true) {
//alert(xmlDoc.documentElement.xml);
}
}

I tried xmlDoc.documentElement.xml but it dont work.
How can I read the entire xml file in a variable?
 
M

Martin Honnen

Sunny said:
I am using this code to load the xml file.
if (document.implementation && document.implementation.createDocument)
{
xmlDoc = document.implementation.createDocument("","",null);
xmlDoc.async="false";

You should assign a boolean value not a string to the async property:
xmlDoc.async = false;
However that blocks the browser while loading the document so that is
usually not a good idea. Consider to use asynchronous loading (async =
true) in a browser environment.
var isLoaded = xmlDoc.load("allcounties_3.xml");
if (isLoaded == true) {
//alert(xmlDoc.documentElement.xml);
}
}

I tried xmlDoc.documentElement.xml but it dont work.
How can I read the entire xml file in a variable?

Well xmlDoc is a variable containing the XML document as a DOM tree.
If you only want a string then I am not sure why you use
createDocument() and the load method, you could use XMLHttpRequest and
simply access responseText.
Or, if you think you need createDocument() and the load method, then you
need to serialize the DOM tree e.g.
var xml = new XMLSerializer().serializeToString(xmlDoc);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top