A) Single <Foo>
element
Do you need list of attributes of a single element?
... if so - do you really need an array?
Simple $('<foo ... />').get(0).attributes
...will give you NamedNodeMap (object) of attributes
B) All elements <Foo>
in the whole (XML) document
@Soufiane Hassou 's answer is showing approach but is missing the inner loop...
Do you need to fetch all possible attribute names of an element (e.g. Product element) inside a whole XML document?
var yourElements = document.getElementsByTagName('Foo'); //get all <Foo> elements
var listOfAttributeNames = []; //prepare empty array for attribute names
var attributeNameBuffer; //buffer for current attribute name in loop
//Loop all elements
for(var i = 0; i < yourElements.length ; ++i){
//Loop all attributes of a current element
for( k = 0 ; k < yourElements[i].attributes.length ; ++k ){
//Temporary store current attribute name
attributeNameBuffer = yourElements[i].attributes[k].name;
//First,
//test if the attribute name does not already exist in our array of names
if( listOfAttributeNames.indexOf(attributeNameBuffer) == -1 )
listOfAttributeNames.push( attributeNameBuffer ); //if not, add it
}
}
console.log(listOfAttributeNames); //display array of attributes in console