XML DOM getNamedItem() 메서드
❮ 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
정의 및 사용
getNamedItem() 메서드는 (namedNodeMap에서) 특정 이름을 가진 노드를 반환합니다.
브라우저 지원
getNamedItem() 메서드는 모든 주요 브라우저에서 지원됩니다.
참고: Internet Explorer 8 및 이전 버전은 이 방법을 지원하지 않습니다.
통사론
namedNodeMap.getNamedItem(nodeName)
매개변수
Parameter | Type | Description |
---|---|---|
nodeName | String | Required. The name of the node to return |
반환 값
Type | Description |
---|---|
Node object | The node with the specified name, , or null if it does not identify any node in the map |
기술적 세부 사항
DOM 버전 | 코어 레벨 1 |
---|
직접 체험해볼 수 있는 데모
❮ NamedNodeMap 객체