Din punc de vedere structural DOM - ul se imparte in trei niveluri :
- Core DOM - modelul standard pentru orice fel de document structurat
 - XML DOM - modelul standard pentru fisere XML + obiecte si propietati ale elemetelor documentului
 - HTML DOM - modelul standard pentru fisere HTML + obiecte si propietati ale elemetelor documentului
 
- Intregul document este un nod de tip document
 - Oricare element XML este un nod de tip element
 - Textul dintr-un fisier XML este un nod de tip text
 - Oricare atribut XML este un nod de tip atribut
 
De exemplu pentru urmatorul XML ,DOM-ul asociat ca avea structura:
<?xml version="1.0" encoding="ISO-8859-1"?>
<bookstore>
<book category="cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="children">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="web">
<title lang="en">XQuery Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyanathan Nagarajan</author>
<year>2003</year>
<price>49.99</price>
</book>
<book category="web" cover="paperback">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>
Proprietati DOM
  - x.nodeName - numele lui x
 - x.nodeValue - valoarea lui x
 - x.parentNode -nodul parinte al lui x
 - x.childNodes - nodurile copii ale lui x
 - x.attributes - nodurile atribut ale lui x
 
Metodele utilizate in DOM
 - x.getElementsByTagName(name) - extrage un element cu numele "name"
 - x.appendChild(node) - se insereaza un nod copil sub nodul x
 - x.removeChild(node) - se sterge un copil din nodul x
 

Niciun comentariu:
Trimiteți un comentariu