<html lang="ko">
<head>
<meta charset="UTF-8">
<title>XML Node</title>
<script>
function loadDoc() {
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if(this.status == 200 && this.readyState == this.DONE) {
findFirstNodeValue(xmlHttp);
}
};
xmlHttp.open("GET", "/examples/media/programming_languages.xml", true);
xmlHttp.send();
}
function findFirstNodeValue(xmlHttp) {
var xmlObj, firstElementNode;
xmlObj = xmlHttp.responseXML; // 요청한 데이터를 XML DOM 객체로 반환함.
// XML 문서 노드의 첫 번째 요소 노드를 반환함.
firstElementNode = xmlObj.documentElement.childNodes[1];
// 해당 노드의 첫 번째 요소 노드의 텍스트 노드의 값을 반환함.
document.getElementById("text").innerHTML = "첫 번째 요소 노드의 텍스트 노드값은 " +
firstElementNode.childNodes[1].firstChild.nodeValue + "입니다.";
}
</script>
</head>
<body>
<h1>nodeValue 속성</h1>
<button onclick="loadDoc()">노드 값 확인!</button>
<p id="text"></p>
</body>
</html>