728x90
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<p id="demo"></p>
<script type="text/javascript">
let xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if(this.readyState == 4 && this.status == 200){
// nodeValFunc( this );
// nodeNameFunc(this);
childNodeFunc(this);
}
}
xhttp.open("GET", "member.xml", true);
xhttp.send();
function nodeValFunc( xml ) {
let num, name;
let txt, numtxt, xmlDoc;
txt = numtxt = '';
xmlDoc = xml.responseXML;
console.log(xmlDoc);
num = xmlDoc.getElementsByTagName("๋ฒํธ");
name = xmlDoc.getElementsByTagName("์ด๋ฆ");
console.log(num.length);
for (i = 0; i < num.length; i++) {
txt += num[i].childNodes[0].nodeValue + "<br>";
numtxt += name[i].childNodes[0].nodeValue + "<br>";
}
document.getElementById("demo").innerHTML = txt + numtxt;
}
function nodeNameFunc( xml ) {
let arr, xmlDoc, txt;
txt = "";
xmlDoc = xml.responseXML;
arr = xmlDoc.documentElement.childNodes;
for (i = 0; i < arr.length; i++) {
if(arr[i].nodeType == 1){
txt += arr[i].nodeName + "<br>";
}
}
document.getElementById("demo").innerHTML = txt;
}
function childNodeFunc( xml ) {
let arr, xmlDoc, txt;
txt = "";
xmlDoc = xml.responseXML;
arr = xmlDoc.getElementsByTagName("๊ณ ๊ฐ")[0];
let len = arr.childNodes.length;
// alert(len);
let fchild = arr.firstChild;
for(i = 0;i < len; i++){
if(fchild.nodeType == 1){
txt += i + " " + fchild.nodeName + "<br>";
}
fchild = fchild.nextSibling;
}
document.getElementById("demo").innerHTML = txt;
}
</script>
</body>
</html>
'๐ ์๋ฐ ์๋ฒ ํ์ด์ง JSP > ๐ธ ์ ์ด์จ XML\JSON' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
2๏ธโฃ ์ ์ด์จ JSON - ๋ฐ์ดํฐ ๊ฐ์ ธ์ค๊ธฐ (0) | 2021.03.09 |
---|---|
1๏ธโฃ ์ ์ด์จ JSON - ๊ธฐ๋ณธ 1 (0) | 2021.03.09 |
3๏ธโฃ XML - ๋ฌธ์์ด ๋์ ๊ณผ ์ค์ XMLํ (0) | 2021.03.09 |
2๏ธโฃ XML - readyState ์ํ, status/stateText ์๋ฒ ์๋ต์ํ (0) | 2021.03.09 |
1๏ธโฃ XML - ๊ธฐ๋ณธ 1 (0) | 2021.03.09 |
๋๊ธ