728x90
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<p id="demo">p tag</p>
<script type="text/javascript">
let xmltext = "<bookstore>" + /*root tag*/
"<book>" + /*node*/
"<title>ํ๋ฌด๋</title>" +
"<author>man</author>" +
"<year>2001</year>" +
"</book>" +
"<book>" + /*node*/
"<title>์ด์์ด์ผ๊ธฐ</title>" +
"<author>man</author>" +
"<year>2001</year>" +
"</book>" +
"</bookstore>";
//alert(xmltext); // XML์ด ์๋๋ผ ๋ฌธ์์ด
let parser, xmlDoc;
parser = new DOMParser();
xmlDoc = parser.parseFromString(xmltext, "text/html");
alert(xmlDoc); //์ค์ XMLํ๋ ๊ฒ
document.getElementById("demo").innerHTML
//= xmlDoc.getElementsByTagName("book")[0].childNodes[0].nodeName; //->title
//= xmlDoc.getElementsByTagName("book")[0].childNodes[1].nodeName; //->author
//= xmlDoc.getElementsByTagName("book")[0].childNodes[0].childNodes[0].nodeValue; // ํ๋ฌด๋
//= xmlDoc.getElementsByTagName("book").length; // ํฐ ๋
ธ๋์
= xmlDoc.getElementsByTagName("book")[0].childNodes.length;
</script>
</body>
</html>
'๐ ์๋ฐ ์๋ฒ ํ์ด์ง JSP > ๐ธ ์ ์ด์จ XML\JSON' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
2๏ธโฃ ์ ์ด์จ JSON - ๋ฐ์ดํฐ ๊ฐ์ ธ์ค๊ธฐ (0) | 2021.03.09 |
---|---|
1๏ธโฃ ์ ์ด์จ JSON - ๊ธฐ๋ณธ 1 (0) | 2021.03.09 |
4๏ธโฃ XML - ์์ฉ (0) | 2021.03.09 |
2๏ธโฃ XML - readyState ์ํ, status/stateText ์๋ฒ ์๋ต์ํ (0) | 2021.03.09 |
1๏ธโฃ XML - ๊ธฐ๋ณธ 1 (0) | 2021.03.09 |
๋๊ธ