function parseXML(xml /* req.responseXML */) { var obj = { _text : "" }; var child = xml.firstChild; while (child) { if (child.nodeName == "#text") { obj._text += child.nodeValue; } else if (child.nodeType == 1) { if (typeof obj[child.nodeName] == "undefined") { obj[child.nodeName] = []; } obj[child.nodeName][obj[child.nodeName].length] = parseXML(child); } child = child.nextSibling; } var att = xml.attributes; var i = 0; if (att) { // there are attributes for (var i = 0; i < att.length; i++) { obj[att[i].name] = att[i].value; } } if (obj._text.match(/^\s*$/)) { delete obj._text; } return obj; }