• 코드:
​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
                    changeTextValue(xmlHttp);
13
                }
14
            };
15
            xmlHttp.open("GET", "/examples/media/programming_languages.xml", true);
16
            xmlHttp.send();
17
        }
18
​
19
        function changeTextValue(xmlHttp) {
20
            var xmlObj, targetNode, result;
21
            xmlObj = xmlHttp.responseXML;   // 요청한 데이터를 XML DOM 객체로 반환함.
22
            // 첫 번째 <priority>요소의 첫 번째 자식 노드를 반환함.
23
            targetNode = xmlObj.getElementsByTagName("priority")[0].firstChild;
24
            document.getElementById("text").innerHTML = targetNode.nodeValue;
25
        }
26
    </script>
27
</head>
28
​
29
<body>
30
​
31
    <h1>노드의 값 확인</h1>
32
    <button onclick="loadDoc()">노드의 값 확인!</button>
33
    <p id="text"></p>
34
    
35
</body>
36
​
37
</html>