XML DOM 길이 속성
❮ NamedNodeMap 객체
예시
다음 코드 조각은 " books.xml "을 xmlDoc에 로드하고 첫 번째 <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 xmlDoc = xml.responseXML;
var x =
xmlDoc.getElementsByTagName("book");
document.getElementById("demo").innerHTML =
"Number of
attributes in the first book element: " +
x.item(0).attributes.length;
}
위 코드의 출력은 다음과 같습니다.
Number of attributes in the first book element:
1
정의 및 사용
길이 속성은 NamedNodeMap의 노드 수를 반환합니다.
통사론
nodemapObject.length
직접 체험해볼 수 있는 데모
❮ NamedNodeMap 객체