๐ ์๋ฐ ์๋ฒ ํ์ด์ง JSP/๐ธ ์ ์ด์จ XML\JSON
4๏ธโฃ XML - ์์ฉ
Meteora_
2021. 3. 9. 19:46
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>