I know individual attributes can be retrieved with the attr() method, but I\'m trying to iterate over all of the attributes for an element. Fo
Pure JS First, your input xml is not valid, but you can fix it by close subitem tags by /
let items = (new DOMParser()).parseFromString(xml,"text/xml").querySelectorAll('item');
items .forEach( (item,i)=> Object.values(item.attributes).forEach(a => {
// your code
console.log(`Item ${i}. attr ${a.name} = ${a.value}`)
}));
let xml=`
-
-
`;
let items = (new DOMParser()).parseFromString(xml,"text/xml").querySelectorAll('item');
items .forEach( (item,i)=> Object.values(item.attributes).forEach(a => {
// your code
console.log(`Item ${i}. attr ${a.name} = ${a.value}`)
}));