javascript and XML...convert a file into a string

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
krraleigh
Forum Commoner
Posts: 86
Joined: Tue Jul 17, 2007 2:52 pm

javascript and XML...convert a file into a string

Post by krraleigh »

Working through the Javascript book "Professional Javascript for Web Developers" by Wrox, author "Zakas".
In particular I am working through his section on how to handle XML processing in Javascript.

The author gives a really good function to handle converting an XML string into a DOM object for processing,
but the book stops short on suggesting a way to handle files. Now I can handle files in two of the three cases
using:

Code: Select all

 
xmldom.load('myfile.xml') for IE &
 
//The DOM 3 Load and Save ..works in Opera.. 
var parser = document.implementation.createLSParser(document.implementation.MODE_SYNCHRONOUS, null);
//add event listener to determine when document has loaded
//code here...however...the load event never fires in 9.5..So I need to address this problem also
parser.parseURI('example.xml');
 
So the question is how do I convert an XML file to a string if my browser is using DOMParser?
Because this method will only take a string:

Code: Select all

 
var parser = new DOMParser();
var xmldom = parser.parseFromString("<root><child/></root>", "text/xml");
// as you can see the above code only take a string, no other options here.
 

thanx kevin
Post Reply