YesYo.com MintState Forums
뒤로    YesYo.com MintState BBS > Tech > Ajax & Issue
검색
멤버이름    오토
비밀번호 
 

간단한 XML 데이타 번역(파싱)

페이지 정보

작성자 MintState 댓글 0건 조회 11,333회 작성일 09-01-05 13:19

본문

간단한 XML 데이타 번역(파싱)

첨부파일에 간단한 예제 첨부

index.html
<HTML>
<HEAD>
	<TITLE>YesYo.com</TITLE>
</HEAD>
<BODY>
<script>
function newXMLHttpRequest() {
	var xmlreq = false;
	if (window.XMLHttpRequest) {
		xmlreq = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		try {
			xmlreq = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e1) {
			try {
				xmlreq = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e2) {
			}
		}
	}
	return xmlreq;
}
function getData() {
	request = newXMLHttpRequest();//req 객체반환
  request.onreadystatechange = function() {
		if (request.readyState == 4) {
			// only if "OK"
			if (request.status == 200) {
				parseResponse(request);
				//alert('dddddd');
			} else {
				alert("There was a problem retrieving the XML data:\n" + request.statusText);
			}
		}
	}
	request.open("GET", "data.xml", true);
	request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	request.send(null);
}

function parseResponse(request) {

	var output = document.getElementById("out"); 
	var outhtml = ""; 
	output.innerHTML = ""; 

	var data = request.responseXML;
	
	var Response = data.getElementsByTagName("Response")[0]; 
	var etc = Response.getElementsByTagName("etc")[0]; 
	var memberCnt = parseInt(etc.getAttribute("memberCnt"), 10);
	outhtml += "memberCnt : "+memberCnt + "<hr />";
	
	var member = etc.getElementsByTagName("member"); 
	
	var lists = Response.getElementsByTagName("lists")[0]; 
	var itemCnt = Math.ceil(lists.getAttribute("itemCnt")); 
	outhtml += "itemCnt : "+itemCnt + "<hr />";

	var item = lists.getElementsByTagName("item"); 
	
	
	
	if(member.length > 0) { 
		for(i=0;i<member.length;i++) {
      var memberValue = etc.getElementsByTagName("member")[i].firstChild.nodeValue;
			outhtml += memberValue + "<br />";
		}
	}
			outhtml += "<hr />";
	if(item.length > 0) { 
		for(i=0;i<item.length;i++) {
      var t1Value = item[i].getElementsByTagName("t1")[0].firstChild.nodeValue;
			outhtml += t1Value + "<br />";
		}
	}
	output.innerHTML = outhtml;
}
</script>
	
<span style="cursor:pointer;" onclick="getData();">Click</span>
<div id="out"></div>
</BODY>
</HTML>


data.xml
<?xml version="1.0" encoding="utf-8"?>
<Response>
	<etc memberCnt='18'>
		<member>A123</member>	
		<member>B123</member>	
		<member>C123</member>	
	</etc>
	<lists itemCnt='12.3'>
		<item>
			<t1>t11</t1>
			<t2>t21</t2>
			<t3>t31</t3>
		</item>	
		<item>
			<t1>t12</t1>
			<t2>t22</t2>
			<t3>t32</t3>
		</item>	
		<item>
			<t1>t13</t1>
			<t2>t23</t2>
			<t3>t33</t3>
		</item>	
		<item>
			<t1>t14</t1>
			<t2>t24</t2>
			<t3>t34</t3>
		</item>	
	</lists>
</Response>
첨부 파일
파일 종류: rar xml파싱.rar (1.2K, 55 views)

댓글목록

등록된 댓글이 없습니다.

Total 32건 2 페이지
Ajax & Issue 목록
번호 제목 글쓴이 조회 날짜
12 MintState 12692 02-19
11 MintState 13715 02-16
10 MintState 15567 02-11
열람중 MintState 11334 01-05
8 MintState 13840 11-17
7 MintState 17559 10-28
6 MintState 9912 10-28
5 MintState 13243 10-28
4 MintState 12752 10-28
3 MintState 8786 10-28
2 MintState 12764 10-28
1 MintState 10179 10-28
게시물 검색
모바일 버전으로 보기
CopyRight ©2004 - 2021, YesYo.com MintState. ™