Hi there,
Seems like Mootools does not do anything special to the xml returned by
Request.XML. On jQuery, for example, you can do xml.find('tagname') and it
wil give you all nodes with that tag name. This works on all browsers. But
in Mootools, you cannot do xml.getElements('tagname'), at least on IE
browsers.
I found somewhere on the Mootools forums a piece of code to override
Resquest.XML, generating a DOM tree of elements representing the XML
structure for browsers that don't support xpath (ie browsers, for example).
The piece of code worked fine, until I have found that image nodes on the
xml cannot be converted to an image node on IE because IE browsers change
that tagname to IMG.
Here is the code I have right now:
/* Extension for parsing XML on IE browsers */
Request.XML = new Class({
Extends: Request,
success: function(text, xml) {
if (xml) {
if(Browser.Features.xpath) {
// some stuff
} else {
xml = this.createXML(xml.documentElement); // ie browsers
}
}
window.xml = xml;
this.onSuccess(xml, text);
},
createXML : function(xml, parent, level) {
if(!parent) {
parent = new Element(xml.nodeName);
level = 'root';
}
level += '>>'+xml.nodeName;
console.log(level);
if(xml.childNodes.length) {
for(var i = 0; i < xml.childNodes.length; i++) {
var son = xml.childNodes[i];
if(son.nodeType == 1) { // Element type
// NodeName
var el = new Element(son.nodeName.replace(':', ''));
// Attributes
if(son.attributes.length) {
for(var j = 0; j < son.attributes.length; j++) {
var property = son.attributes[j].nodeName;
var value = son.attributes[j].nodeValue;
el.setProperty(property, value);
}
}
// Value
if (son.firstChild && son.firstChild.nodeType==3) {
if (son.firstChild.nodeValue) {
el.set({'text' : son.firstChild.nodeValue});
}
}
if (son.nodeName == 'fileentryid') console.log('docId:'+el.get('text'));
parent.grab(el);
this.createXML(son, el, level);
}
}
}
return parent;
}
});
Then, as I mentioned, I can do things like :
this.gallery.numPhotoItems =
xml.getElement('totalEntries').get('text').toInt();
This works perfect on IE browsers.... unless there is an image tag on the
xml... and I cannot change that.
Is there another way of enabling getElement(s) functions on xml trees on all
browsers without converting them to DOM trees?
Any ideas?
Thanks a lot..
PS: I couldn't find the url for the paste site