๐ป
JavaScript ์ ์ดํด - [AJAX] XMLHttpRequest.responseXML ๋ณธ๋ฌธ
KITRI/JAVASCRIPT
JavaScript ์ ์ดํด - [AJAX] XMLHttpRequest.responseXML
๋ํจ๋ 2020. 7. 16. 16:50https://developer.mozilla.org/ko/docs/Web/API/XMLHttpRequest/responseXML
responseXML.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="responseXML.js"></script>
</head>
<body>
<h3>์๋ต๋ด์ฉ</h3>
<form>
<input id="sndRet" type="button" value="์ ๋ณด์์ฒญ" onclick="startRequest()"/>
</form>
<div id="disp"></div>
</body>
</html>
responseXML.js
/**
*
*/
/**
*
*/
function startRequest(){
//alert("OK");
//๊ฐ์ฒด XMLHttpRequest -> ์น๋ธ๋ผ์ฐ์
var xhr = null;
var arr = new Array();
if(window.XMLHttpRequest){
xhr = new XMLHttpRequest;
}else{
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
arr.push(xhr);
alert(arr.join("\n"));
xhr.open("GET","responseXML.xml", true);
xhr.send();
xhr.onreadystatechange = resultProcess;
}
function resultProcess(){
if(xhr.readyState==4 && xhr.status==200){
arr.put(xhr.responseXML);
//alert(ar.join("\n"));
var xmlDoc = xhr.responseXML;
var studentList = xmlDoc.getElementsByTagName("student");
var disp = document.getElementById("disp");
for(var i=0; i<studentList.length; i++){
var student= studentList[i];
var subElement = student.childNodes;
var div = document.createElement("div");
for(var j=0; j<subElement.length; j++){
var span = document.createElement("span");
span.innerHTML = subElement[i].childNodes[0].nodeValue +" ";
div.appendChild(span);
}
}
disp.appendChild(div);
}
}
responseXML.xml
<?xml version="1.0" encoding="UTF-8"?>
<member xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.example.org/responseXML responseXML.xsd"
xmlns="http://www.example.org/responseXML">
<student>
<stdNumber>1001</stdNumber>
<stdName>ํ๊ธธ๋</stdName>
<score>95</score>
</student>
<student>
<stdNumber>1002</stdNumber>
<stdName>๊น๊ธธ๋</stdName>
<score>90</score>
</student>
<student>
<stdNumber>1003</stdNumber>
<stdName>๋ฐ๊ธธ๋</stdName>
<score>80</score>
</student>
</member>
responseXML.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/responseXML"
xmlns="http://www.example.org/responseXML"
elementFormDefault="qualified">
<xsd:element name="member" type="member"/>
<xsd:complexType name="member">
<xsd:sequence>
<xsd:element name="student" minOccurs="1" maxOccurs="unbounded" type="student"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="student">
<xsd:sequence>
<xsd:element name="stdNumber" minOccurs="1" maxOccurs="1" type="xsd:string"/>
<xsd:element name="stdName" minOccurs="1" maxOccurs="1" type="xsd:string"/>
<xsd:element name="score" minOccurs="1" maxOccurs="1" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
๋ฐ์ํ
'KITRI > JAVASCRIPT' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
JavaScript ์ ์ดํด - [AJAX] Kakao ์ง๋ Javscript API ์ด์ฉํด์ ์ง๋๊ทธ๋ฆฌ๊ธฐ (0) | 2020.07.20 |
---|---|
JavaScript ์ ์ดํด - [AJAX] ๊ธฐ์์ฒญ ๋ฐ์ดํฐ Parsing (0) | 2020.07.20 |
JavaScript ์ ์ดํด - [AJAX] ํ์ค ๋ต๊ธ ๋ฌ๊ธฐ(CRUD) (0) | 2020.07.16 |
JavaScript ์ ์ดํด - [AJAX] XHR(XMLHttpRequest) (0) | 2020.07.16 |
JavaScript ์ ์ดํด - [AJAX] JSON ๊ฐ์ฒด ๋ค๋ฃจ๊ธฐ (0) | 2020.07.15 |
Comments