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/