views:

397

answers:

1

Is there a way to get the name of an attribute of an XML node using javascript. Lets take this as a sample XML

<?xml version="1.0" encoding="UTF-8"?>
<Employees>  
     <Count name="EmployeeCount">100</Count>
     <employee id="9999" >Harish</employee>
     <Salary>
      <year id="2000">50 Grands</year>
      <year id="2001">75 Grands</year> 
      <year id="2002">100 Grands</year>
     </Salary>
    </Employees>

I am loading XML using ActiveXObject.As you can see not all elements have attributes.I need to list all attributes like

name
id
id
id
id
+1  A: 

Try this:

var nodes = xml.selectNodes("//@*")
for(var i=0; i < nodes.length; i++)
{
    alert(nodes[i].nodeName);
}
Rubens Farias
thanks for it.Got the solution
Harish