Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Read entire xml file

Reply
Thread Tools

Read entire xml file

 
 
Sunny
Guest
Posts: n/a
 
      10-06-2008
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?
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      10-06-2008
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/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FAQ 5.29 How can I read in an entire file all at once? PerlFAQ Server Perl Misc 0 03-16-2011 04:00 AM
FAQ 5.29 How can I read in an entire file all at once? PerlFAQ Server Perl Misc 0 01-26-2011 05:00 AM
xml file formatting from entire file in single string David Southwell Ruby 3 11-04-2009 04:57 AM
readlines() doesn't read entire file Jeremy Python 3 07-15-2005 12:14 AM



Advertisments