0

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
  • As I understand you need list all attributes but in the example you post "EmployeeCount" wich is the value of the attribute "name"... not the attribute itself... if I'm correct the output should be: name id id id id right? Commented Oct 10, 2009 at 16:59

1 Answer 1

1

Try this:

var nodes = xml.selectNodes("//@*")
for(var i=0; i < nodes.length; i++)
{
    alert(nodes[i].nodeName);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.