본문 바로가기
Mobile Programming/HTML/JavaScript

JavaScript XML(URL) 파싱

by 학수씨 2012. 2. 10.

 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Javascript DOM Test</title>
<script>
 
function on_LoadStart(event)
{
 alert("loadStart");
}
 
function on_LoadError(event)
{
 alert("loadError");
}
function on_CompleteXMLData(event)
{
 alert("complete");
 
 //var zzz = event.srcElement.responseText;
 var zzz = this.responseText;
 
 if(this.responseXML != null)
 {
  var list  =document.getElementById("list");
  var imageList = this.responseXML.getElementsByTagName("image");
  
  var strList  ="";
  for(var i=0;i<imageList.length;i++)
  {
   strList+= i+", "+imageList[i].attributes["src"].nodeValue+"<br>";
  }
  
  list.innerHTML =strList;
 }
 
}
 
function on_Loadend()
{
 alert("on_LoadEnd");
}
 
function on_Click()
{
 var client     = new XMLHttpRequest();
 client.onloadstart  = on_LoadStart;
 client.onerror   = on_LoadError;
 client.onload   = on_CompleteXMLData;
 client.onloadend  = on_Loadend;
  
  client.open("GET", "http://www.ncqr.net/real/1.xml", true);
 client.send();
}
</script>
</head>
<body>
<input type="button" value="load" onClick="on_Click()"><br>
<div id="list" style="width:400px;height:100px">    
</div>
</body>

 </html>

댓글