xml 파서
Language/JAVASCRIPT 2011. 6. 9. 10:57<script type="text/javascript">
<!--
function getXMLObject() {
var xDoc = null;
// 파이어폭스
if (document.implementation && document.implementation.createDocument) {
xDoc = document.implementation.createDocument("","",null);
// 익스플로러
}else if (typeof ActiveXObject != "undefined") {
var msXmlAx = null;
try {
//최신버젼
msXmlAx = new ActiveXObject("Msxml2.DOMDocument");
}catch (e){
//구 버젼
msXmlAx = new ActiveXObject("Msxml.DOMDocument");
}
xDoc = msXmlAx;
}
return xDoc;
}
var objXdoc = getXMLObject();
objXdoc.async = false;
objXdoc.load('xml2.xml');
var XmlDoc = objXdoc.getElementsByTagName('item');
document.write(XmlDoc[0].getAttribute("name"));
document.write("<br />");
document.write(XmlDoc[0].getElementsByTagName('title')[0].firstChild.data);
//-->
</script>
==============================================================================================
<?xml version="1.0" encoding="utf-8"?>
<product>
<item name="1">
<title>a</title>
<etime>b</etime>
<stime>c</stime>
<img>d</img>
<link>e</link>
</item>
<item name="2">
<title>aa</title>
<etime>b</etime>
<stime>c</stime>
<img>d</img>
<link>e</link>
</item>
<item name="3">
<title>aaa</title>
<etime>b</etime>
<stime>c</stime>
<img>d</img>
<link>e</link>
</item>
</product>
<!--
function getXMLObject() {
var xDoc = null;
// 파이어폭스
if (document.implementation && document.implementation.createDocument) {
xDoc = document.implementation.createDocument("","",null);
// 익스플로러
}else if (typeof ActiveXObject != "undefined") {
var msXmlAx = null;
try {
//최신버젼
msXmlAx = new ActiveXObject("Msxml2.DOMDocument");
}catch (e){
//구 버젼
msXmlAx = new ActiveXObject("Msxml.DOMDocument");
}
xDoc = msXmlAx;
}
return xDoc;
}
var objXdoc = getXMLObject();
objXdoc.async = false;
objXdoc.load('xml2.xml');
var XmlDoc = objXdoc.getElementsByTagName('item');
document.write(XmlDoc[0].getAttribute("name"));
document.write("<br />");
document.write(XmlDoc[0].getElementsByTagName('title')[0].firstChild.data);
//-->
</script>
==============================================================================================
<?xml version="1.0" encoding="utf-8"?>
<product>
<item name="1">
<title>a</title>
<etime>b</etime>
<stime>c</stime>
<img>d</img>
<link>e</link>
</item>
<item name="2">
<title>aa</title>
<etime>b</etime>
<stime>c</stime>
<img>d</img>
<link>e</link>
</item>
<item name="3">
<title>aaa</title>
<etime>b</etime>
<stime>c</stime>
<img>d</img>
<link>e</link>
</item>
</product>
'Language > JAVASCRIPT' 카테고리의 다른 글
firefox, IE 이벤트(event) 얻기 (0) | 2011.06.14 |
---|---|
자바스크립트 이벤트 키코드표(keyCode ) (0) | 2011.06.14 |
쿠키 / 팝업 생성 (0) | 2011.05.13 |
주민번호로 나이/성별 구하기 (0) | 2011.05.11 |
파이어폭스(Firefox) / IE : getYear 와 getFullYear 의 차이점 (0) | 2011.05.11 |