I'm trying to write a javascript routine to crawl an XML document (of unknown elements) and parse out name/value pairs where
"<nodename>nodevalue</nodename>"
would come out as
"nodename=nodevalue".
What I have works great through the second element, then it stops traversing. I feel like I'm close but I just cant get past this point. Any help would be appreciated.
<html>
<head>
<script>
function main() {
function dom(xml) {
if (window.DOMParser) {
parser=new DOMParser();
parser.preserveWhiteSpace=false;
doc=parser.parseFromString(xml,"text/xml");
} else {
doc=new ActiveXObject("Microsoft.XMLDOM");
doc.async=false;
doc.preserveWhiteSpace=false;
doc.loadXML(xml);
}
return crawl(doc);
}
function crawl(node) {
if (typeof node=='object') {
if (node.hasChildNodes()) {
var x=node.childNodes;
for (i=0;i<x.length;i++) {
if (x[i].hasChildNodes()) {
alert(x[i].nodeName + '=' + x[i].childNodes[0].nodeValue);
}
crawl(x[i]);
}
}
}
}
return dom(document.body.innerHTML);
}
</script>
</head>
<body onload="main();">
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<AccountQueryBalanceResponse xmlns="https://live.domainbox.net/">
<AccountQueryBalanceResult>
<ResultCode>100</ResultCode>
<ResultMsg>Account Balance Queried Successfully</ResultMsg>
<TxID>8ffc9a39-bf7f-477d-a780-76de9fdd49dd</TxID>
<Balance>81.84</Balance>
<CreditLimit>0.00</CreditLimit>
<FundsHeld>0.00</FundsHeld>
<AvailableBalance>81.84</AvailableBalance>
<CurrencyCode>USD</CurrencyCode>
<AccountType>Prepayment</AccountType>
</AccountQueryBalanceResult>
</AccountQueryBalanceResponse>
</soap:Body>
</soap:Envelope>
</body>
</html>