Mozilla, nodes
Working on a new ajax model for flapping crane.
One note for anyone who has to deal with XML cross-browser issues: Gecko browsers (Firefox, Mozilla, etc) count things like newlines and spaces in an XML file as nodes. While it adheres to spec, it is (as far as I can tell) lame and asinine. So, to filter them out, create an array something like this, assuming xmlTags is an XML object:
for (i=0;i<xmlTags[i].length;i++) {
if ( ( xmlTags[i].nodeType != 3 ) && ( xmlTags[i].nodeType != 8 ) ) {
xmlData[xmlTags[i].nodeName] = trim(xmlTags[i].firstChild.data);
}
}
The key part is checking the node type. Type 3 and 8 are for text nodes and comment nodes. This only works because the nodes I care about are element nodes.
My original plan was to just check for the return value of xmlTags[i].firstChild, but this way seems better.
P.S. — Sorry, here’s trim():
function trim(text) {
try {
return text.replace(/^\s*(.*?)\s*$/g, '$1');
}
catch (e) {
return text;
}
}