By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,741 Members | 2,033 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,741 IT Pros & Developers. It's quick & easy.

Read entire xml file

P: n/a
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?
Oct 6 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Sunny wrote:
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);

--

Martin Honnen
http://JavaScript.FAQTs.com/
Oct 6 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.