There doesn\'t seem to be any useful documentation out there about parsing XML in Mootools. Either it\'s so stupidly easy nobody could be bothered to mention it, or it\'s so
This is a rather old question but I recently had the same problem, so I'd like to share my solution.
The responseXML
variable you receive from Request
is simply the unaltered XML response from your browser. Under IE (up to version 9), you'll receive an IXMLDOMDocument object. I found that the easiest way to convert this object to a MooTools Element
tree is the following:
function(responseText, responseXML) {
var doc = responseXML.documentElement;
if (doc.xml) {
doc = new Element('div', { html: doc.xml }).getFirst();
}
// Now you can use 'doc' like any other MooTools Element
}
Alternatively, you can use IE's DOMParser
which might be more efficient:
function(responseText, responseXML) {
var doc = responseXML.documentElement;
if (doc.xml) {
var parser = new DOMParser();
var html = parser.parseFromString(doc.xml, 'text/xml');
doc = document.id(html.documentElement);
}
// Now you can use 'doc' like any other MooTools Element
}
In MooTools Forge there is a plugin for converting XML to a JavaScript object:
http://mootools.net/forge/p/xml2js_converter