AJAX and the Mozilla XMLHttpRequest object
September 26, 2005 – 8:19 pmI am just learning the full in’s and out’s of the javascript DOM and XMLHttpRequest object model for Mozilla. I wanted to be able to duplicate the results the XMLHttpRequest Object returns. I thought I just wanted XML, however it turns out the request object automatically places the xml returned into the DOM parser and returns that object. There may be a way to turn this off, I’m not sure yet, however here is the code to simulate the DOM parsing of a javascript string:
[code lang="javascript"]
var xmlString = '
'
'
'
'
'
var parser = new DOMParser();
var xmlDoc = parser.parseFromString(xmlString, "application/xml");
[/code]
It should be noted that the javascript var uses “+”’s to avoid a very long xml line (since newlines will break the syntax).
I found this as a good quick reference to the parsing and serializing of XML data. Apple also has a nice tutorial available on their website.
Sorry, comments for this entry are closed at this time.