I can't see why it's not working but it's difficult to read. Here's a working example:
Code:
<html>
<head>
<title>Show Categories</title>
<script type="text/javascript">
function getXmlFromServer()
{
return "<Categories>"
+ "<Category><name>NOTICE OF VALUATION OF REAL ASSETS</name></Category>"
+ "<Category><name>NOTICE OF INTEREST/CHANGES IN INTEREST</name></Category>"
+ "<Category><name>NOTICE OF BOOK CLOSURE DATE</name></Category>"
+ "<Category><name>Notice of 3 Consecutive Years Losses</name></Category>"
+ "</Categories>";
}
function getParser()
{
//Here I would use something like zXML
//to allow cross-browser usage
var oDom = new ActiveXObject("msxml2.domdocument.3.0");
oDom.setProperty("SelectionLanguage", "XPath");
oDom.async = false;
return oDom;
}
function showCategories()
{
var oDom = getParser();
var sXml = getXmlFromServer();
var bLoaded = oDom.loadXML(sXml);
if (!bLoaded)
{
alert(oDom.parseError.reason);
return;
}
//alert(oDom.xml);
var arrData = [];
//Using DOM
var colCategories = oDom.documentElement.getElementsByTagName("Category");
//alert(colCategories.length);
for (var i = 0, l = colCategories.length; i < l; i++)
{
var oCategory = colCategories[i];
var oName = oCategory.getElementsByTagName("name")[0];
arrData[i] = oName.firstChild.nodeValue;
}
alert(arrData.join("|"));
//Using XPath
var colNames = oDom.selectNodes("/Categories/Category/name");
for (var i = 0, l = colNames.length; i < l; i++)
{
arrData[i] = colNames[i].firstChild.nodeValue;
}
alert(arrData.join("|"));
}
</script>
</head>
<body onload="showCategories();">
</body>
</html>
--
Joe (
Microsoft MVP - XML)