XML DOM item() 메서드
❮ NamedNodeMap 객체
예시
다음 코드 조각은 " books.xml "을 xmlDoc에 로드하고 <book> 요소를 반복하며 category 속성의 값을 인쇄합니다.
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, att, xmlDoc,
txt;
xmlDoc = xml.responseXML;
txt = "";
x = xmlDoc.getElementsByTagName('book');
for (i = 0; i < x.length; i++) {
att = x.item(i).attributes.getNamedItem("category");
txt += att.value + "<br>";
}
document.getElementById("demo").innerHTML = txt;
}
위 코드의 출력은 다음과 같습니다.
cooking
children
web
web
정의 및 사용
item() 메서드는 노드 목록의 지정된 인덱스에 있는 노드를 반환합니다.
통사론
item(index)
Parameter | Description |
---|---|
index | The index |
직접 체험해볼 수 있는 데모
❮ NamedNodeMap 객체