• 코드:
​x
 
1
<!DOCTYPE html>
2
<html lang="ko">
3
​
4
<head>
5
    <meta charset="UTF-8">
6
    <title>XML Node</title>
7
    <script>
8
        function loadDoc() {
9
            var xmlHttp = new XMLHttpRequest();
10
            xmlHttp.onreadystatechange = function() {
11
                if(this.status == 200 && this.readyState == this.DONE) {
12
                    findFirstNodeValue(xmlHttp);
13
                }
14
            };
15
            xmlHttp.open("GET", "/examples/media/programming_languages.xml", true);
16
            xmlHttp.send();
17
        }
18
​
19
        function findFirstNodeValue(xmlHttp) {
20
            var xmlObj, firstElementNode;
21
            xmlObj = xmlHttp.responseXML;       // 요청한 데이터를 XML DOM 객체로 반환함.
22
            // XML 문서 노드의 첫 번째 요소 노드를 반환함.
23
            firstElementNode = xmlObj.documentElement.childNodes[1];
24
            // 해당 노드의 첫 번째 요소 노드의 텍스트 노드의 값을 반환함.
25
            document.getElementById("text").innerHTML = "첫 번째 요소 노드의 텍스트 노드값은 " + 
26
                firstElementNode.childNodes[1].firstChild.nodeValue + "입니다.";
27
        }
28
    </script>
29
</head>
30
​
31
<body>
32
​
33
    <h1>nodeValue 속성</h1>
34
    <button onclick="loadDoc()">노드 값 확인!</button>
35
    <p id="text"></p>
36
    
37
</body>
38
​
39
</html>