• 코드:
​x
 
1
<!DOCTYPE html>
2
<html lang="ko">
3
​
4
<head>
5
    <meta charset="UTF-8">
6
    <title>XML Node List</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
                    findNamedNodeMap(xmlHttp);
13
                }
14
            };
15
            xmlHttp.open("GET", "/examples/media/programming_languages.xml", true);
16
            xmlHttp.send();
17
        }
18
​
19
        function findNamedNodeMap(xmlHttp) {
20
            var xmlObj, attrList;
21
            xmlObj = xmlHttp.responseXML; // 요청한 데이터를 XML DOM 객체로 반환함.
22
            // 첫 번째 <version>요소의 모든 속성을 리스트 형태로 반환함.
23
            attrList = xmlObj.getElementsByTagName("version")[0].attributes;
24
            document.getElementById("text").innerHTML =     // 속성 리스트에서 status 속성의 값을 반환함.
25
            "첫 번째 version 요소의 status 속성값은 " + attrList.getNamedItem("status").nodeValue + "입니다.";   
26
        }
27
    </script>
28
</head>
29
​
30
<body>
31
​
32
    <h1>속성 리스트</h1>
33
    <button onclick="loadDoc()">속성 리스트 확인!</button>
34
    <p id="text"></p>
35
    
36
</body>
37
​
38
</html>