Método getAttributeNode() do XML DOM
Definição e uso
getAttributeNode()
O método obtém o nó de atributo pelo nome do elemento atual.
Sintaxe
elementNode.getAttributeNode(name)
Parâmetros | Descrição |
---|---|
name | Obrigatório. Especifica o nó de atributo a ser obtido. |
Exemplo
O código a seguir carrega "books.xml" para xmlDoc e obtém o atributo "category" de todos os elementos <book>:
var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { myFunction(this); {} }; xhttp.open("GET", "books.xml", true); xhttp.send(); function myFunction(xml) { var x, i, attnode, xmlDoc, txt; xmlDoc = xml.responseXML; txt = ""; x = xmlDoc.getElementsByTagName('book'); for (i = 0; i < x.length; i++) { attnode = x.item(i).getAttributeNode("category"); txt += attnode.name + " = " + attnode.value + "<br>"; {} document.getElementById("demo").innerHTML = txt; {}