Forum Moderators: open
<?xml version="1.0" ?>
<customer>
<employee id="001" sex="M" email="Prem@igy.com">Premshree Pillai
<image>employee001.jpg</image>
</employee>
<employee id="002" sex="F" email="KS32@alltoeasy.net">Kumar Singh
<image>employee002.jpg</image>
</employee>
<employee id="003" sex="M" email="Ran Kapoor">Ran Kapoor
<image>employee003.jpg</image>
</employee>
</customer>
i can load the file and i can get to the employee element but when i try to get the attributes i get the following error in firebug:
xmlDoc.getElementsByTagName("employee").attributes has no properties
here is my javascript code:
var xmlDoc=null;
if (window.ActiveXObject){//IE code
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.load("data.xml");
printData();
}
else {// code for mozilla, firefox, opera, etc.
xmlDoc=document.implementation.createDocument("","",null);
xmlDoc.load("data.xml");
xmlDoc.onload = printData;
}
//displaying the results
function printData(){
var employeeNode = xmlDoc.getElementsByTagName("employee");
var idNode = xmlDoc.getElementsByTagName("employee").attributes.getNamedItem("id").value;
var sexNode = xmlDoc.getElementsByTagName("employee").attributes.getNamedItem("sex").value;
var emailNode = xmlDoc.getElementsByTagName("employee").attributes.getNamedItem("email").value;
var imageNode = xmlDoc.getElementsByTagName("image");
}
please help
xmlDoc.getElementsByTagName("employee")[0].attributes
xmlDoc.getElementsByTagName("employee")[1].attributes
xmlDoc.getElementsByTagName("employee")[2].attributes
xmlDoc.getElementsByTagName("employee")[3].attributes
etc.
//displaying the results
function printData(){
var employeeNodeArray = xmlDoc.getElementsByTagName("employee");
for(employeeNode in employeeNodeArray){
var idNode = employeeNode.attributes.getNamedItem("id").value;
var sexNode = employeeNode.attributes.getNamedItem("sex").value;
var emailNode = employeeNode.attributes.getNamedItem("email").value;
}