728x90

์ฝ๋ ํผ์น๊ธฐ ->
๋๋ณด๊ธฐ
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style type="text/css">
#id{
background-color : blue;
}
</style>
</head>
<body>
<div id="books"></div>
<script type="text/javascript">
let xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if(this.readyState == 4 && this.status == 200){
xmlFunc(this);
}
}
xhttp.open('GET','books.xml',true);
xhttp.send();
function xmlFunc(xml) {
let xmlDoc =xml.responseXML;
let rootTagName = xmlDoc.documentElement.nodeName;
let nodeArr = xmlDoc.documentElement.childNodes;
let nodeName;
for (i = 0; i < nodeArr.length; i++) {
if(nodeArr[i].nodeType == 1){
nodeName =nodeArr[i].nodeName;
}
}
//Table line
let out = "<table border= '4'>";
out += "<col width='80'><col width='160'><col width='150'><col width='200'>";
out += "<tr>";
out += "<th>์ฑ
์์</th>";
columnName = xmlDoc.getElementsByTagName( nodeName )[0];
let child = columnName.firstChild;
for (i = 0; i < columnName.childNodes.length; i++) {
if(child.nodeType == 1){
out += "<th>" + child.nodeName + "</th>";
}
child = child.nextSibling;
}
out += "</tr>";
//Data line
let len = xmlDoc.getElementsByTagName(nodeName).length;
for (var i = 0; i < len; i++) {
out += "<tr>";
out += "<th>" + (i + 1) + "</th>";
let dataArr = xmlDoc.getElementsByTagName(nodeName)[i]; //๊ฐ book๋ค์ ๊ฐ์ ธ์ค๊ฒ๋จ
child = dataArr.firstChild;
for ( j = 0; j < dataArr.childNodes.length; j++) {
if (child.nodeType == 1) {
out += "<td>" + child.childNodes[0].nodeValue + "</td>";
}
child =child.nextSibling;
}
out += "</tr>";
}
out += "</table>";
document.getElementById("books").innerHTML = out;
}
</script>
</body>
</html>
books.xml
์ฝ๋ ํผ์น๊ธฐ ->
๋๋ณด๊ธฐ
<?xml version="1.0" encoding="UTF-8"?>
<books>
<book>
<title>Lord of the ring</title>
<author>jf.tolkin</author>
<price>12$</price>
</book>
<book>
<title>Harry Porter</title>
<author>Joanne Rowling</author>
<price>20$</price>
</book>
<book>
<title>The little Prince</title>
<author>Saint-Exupรฉry</author>
<price>9$</price>
</book>
<book>
<title>And Then There Were None</title>
<author>Agatha Christie</author>
<price>16$</price>
</book>
<book>
<title>The Da Vinci Code</title>
<author>Dan Brown</author>
<price>30$</price>
</book>
</books>
'๐ ์๋ฐ ์๋ฒ ํ์ด์ง JSP > ๐ธ ์ ์ด์จ XML\JSON' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
3๏ธโฃ ์ ์ด์จ JSON - ๋๊ตฌํ ๋ฐ์ดํฐ ๊ฐ์ ธ์ค๊ธฐ (0) | 2021.03.09 |
---|---|
2๏ธโฃ ์ ์ด์จ JSON - ๋ฐ์ดํฐ ๊ฐ์ ธ์ค๊ธฐ (0) | 2021.03.09 |
1๏ธโฃ ์ ์ด์จ JSON - ๊ธฐ๋ณธ 1 (0) | 2021.03.09 |
4๏ธโฃ XML - ์์ฉ (0) | 2021.03.09 |
3๏ธโฃ XML - ๋ฌธ์์ด ๋์ ๊ณผ ์ค์ XMLํ (0) | 2021.03.09 |
๋๊ธ