Javascript Source
function getXMLDocument() {
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;
}
function xDocHandler () {
var xDocPath = 'test.xml';
this.objXdoc;
this.xDoc = getXMLDocument
this.objXdoc = this.xDoc();
this.objXdoc.async = false;
this.objXdoc.load(xDocPath);
}
function xDocNodeSearch(str) {
var xDoc = new xDocHandler();
var XmlDoc = xDoc.objXdoc.getElementsByTagName('item');
var cnt = XmlDoc.length;
for (var i = 0; i < cnt; i++) {
if (XmlDoc[i].getAttribute('name') == str) {
var alts = '[메세지] ' + xDoc.objXdoc.getElementsByTagName('msg')[i].firstChild.data;
alts += '\n\n[링크]' + xDoc.objXdoc.getElementsByTagName('link')[i].firstChild.data;
alert(alts);
}
}
}
xDocNodeSearch('test');XML Source : test.xml<?xml version="1.0" encoding="euc-kr" ?> <message> <item name="test"> <msg>안녕하세요. Syaku 블로그 입니다.</msg> <link>http://blog.naver.com/syaku</link> </item> <item name="test2"> <msg>안녕하세요. 샤쿠 블로그 입니다.</msg> <link>http://blog.naver.com/syaku</link> </item> </message>출처 : http://syaku.tistory.com/trackback/13
'ETC' 카테고리의 다른 글
| 이클립스 eclipse 실행시 에러 - Failed to create the Java Virtual Machine (0) | 2011.08.08 |
|---|---|
| 이미지(그림)와 글자의 높낮이를 중간에 맞추기 (0) | 2011.08.04 |
| JAVA 이것저것~!! (0) | 2011.07.25 |
| input 박스등 테두리 투명, 내용 수정 안되도록 읽기만 가능하게 (0) | 2011.07.22 |
| HTML CSS 자바스크립트 J스크립트 사전 (0) | 2011.07.22 |