Skip to content

Latest commit

 

History

History
47 lines (39 loc) · 2.09 KB

File metadata and controls

47 lines (39 loc) · 2.09 KB

XML DOM

  • XML을 오브젝트로 표현
  • platform- and language- independent
  • 모든 XML elements의 object, property, method (interface)를 정의한다.

DOM (Document Object Model)

일종의 interface, API로 볼 수 있다. 특정 os에 dependent하지 않고 모든 플랫폼에서 이용가능하다. (independent)
다이나믹하게 접근/업데이트 가능하다.

  • Core DOM / HTML DOM / XML DOM

XML DOM nodes

  • XML 문서 안 모든 것은 node이다.
  • 전체 document는 document node이다.
  • 모든 XML element는 element node이다.
  • XML element안에 있는 text는 text node이다.
  • 모든 attribute는 attribute node이다.
  • comments는 comment node이다.

XML DOM node tree

  • XML DOM은 XML document를 tree 구조 로 본다. -> node-tree
  • 모든 node는 tree를 통해 access가능하다. - modify, delete, create 가능

XML DOM Parser

  • XML parser는 XML을 읽고, XML DOM 오브젝트로 컨버트한다. -> 자바스크립트로 접근 가능하다.
    -> XML 문서를 tree로 바꿔주는 역할.
  • 대부분 브라우저는 built-in XML parser를 갖고 있다.

XML DOM Node properties

  • x.nodeName: node x의 이름
  • x.nodeValue: node x의 value
  • x.parentNode: x의 parent node
  • x.childNodes: x의 child node (s가 붙음!! 여러 개 존재 가능하다. array 형식)
  • x.attributes: node x의 attributes

XML DOM Node methods

  • x.getElementByTagName(name): x의 sub-tree에서 node이름이 name인 모든 element 모두 가져온다.
  • x.appendChild(node): x에 child를 붙인다. (x의 child node가 된다.)
  • x.removeChild(node): x의 child node를 없앤다. (해당 child node에 sub-tree가 있을 경우 같이 없앤다.)
Node 타입 nodeName 리턴 nodeValue 리턴
1 Element element name null
2 Attr attribute name attribute value
3 Text #text content of node
8 Comment #comment comment text
9 Document #document null