관리 메뉴

nkdk의 세상

dom에 대하여.. 본문

My Programing/XML

dom에 대하여..

nkdk 2008. 3. 8. 02:06
http://www.quirksmode.org/

dom 참고 사이트입니다.
dom.xml
<?xml version="1.0" encoding="EUC-KR"?>
<중앙>
<교육장 구분="자바">
<성격>자바로 웹을 구현</성격>
<인원>30명</인원>
<기간>10개월</기간>
</교육장>
<교육장 구분="오피스">
<성격>오피스로 업무처리</성격>
<인원>10명</인원>
<기간>3개월</기간>
</교육장>
</중앙>

dom.html


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">


<script language="javascript">
var objDOM = new ActiveXObject("MSXML.DOMDocument");
objDOM.load("dom.xml");

//노드의 이름을 알려주는 함수
function show1(){
var objNode=objDOM.documentElement;
alert("노드명:" + objNode.nodeName + ", 값:" + objNode.nodeValue);
}

//노드의 값을 알려주는 함수
function show2(){
var objNode=objDOM.documentElement.firstChild;
document.write("1.노드명:" + objNode.nodeName);
document.write(", 속성값:" + objNode.getAttribute("구분"));
document.write("
");
document.write("2.노드명:" + objNode.childNodes[0].nodeName);
document.write(", 값:" + objNode.childNodes[0].firstChild.nodeValue);
document.write("
");
document.write("3.노드명:" + objNode.childNodes[1].nodeName);
document.write(", 값:" + objNode.childNodes[1].firstChild.nodeValue);
document.write("
");
document.write("4.노드명:" + objNode.childNodes[2].nodeName);
document.write(", 값:" + objNode.childNodes[2].firstChild.nodeValue);
document.write("

");

document.write("5.노드명:" + objNode.nextSibling.childNodes[0].nodeName);
document.write(", 값:" + objNode.nextSibling.childNodes[0].firstChild.nodeValue);//nextSibling.은 다음 번째 형제로 넘어옴.
document.write("

");
document.write("부모 노드:"+ objNode.parentNode.nodeName);//parentNode 부모 노드로 가기

}

</script>

Dom의 노드 인터페이스의 속성 예



<input type="button" value="요소 연습 1" onClick="show1()">

<input type="button" value="요소 연습 2" onClick="show2()">


</html>