Document Object Model DOM An Abstract Data Structure
Document Object Model (DOM): An Abstract Data Structure for XML data Alex Dekhtyar Department of Computer Science University of Kentucky
About Jobs for B. S. graduates often require work with XML Teach XML in undergraduate curriculum n Databases n Web Programming n Data Structures
Outline XML Syntax XML as a tree Document Object Model (DOM) DOM API
XML Meta-language for encoding information Information, content XML elements Opening tags: <name> Closing tags: <name/> Emply elements: <p/> ordered <faculty> <name> <first> Alexander </first> <middle> M. </middle> <last> Dekhtyar</last> </name> <dept> Computer Science </dept> <course> <sem> Spring 2007 </sem> <code> CS 405 </code> <title> Database systems </title> </course> </faculty>
XML Meta-language for encoding information Information, content XML elements Opening tags: <name> Closing tags: <name/> Emply elements: <p/> ordered Attributes Additional information unordered <faculty id =“ 27” > <name origin=“Ukraine”> <first> Alexander </first> <middle> M. </middle> <last> Dekhtyar</last> </name> <dept> Computer Science </dept> <course> <sem> Spring 2007 </sem> <code> CS 405 </code> <title> Database systems </title> </course> </faculty>
XML § Structure § nested elements § Well-formed XML § correctly nested elements § World Wide Web Consortium (W 3 C) § recommendation § XML 1. 0, 1998 <faculty id =“ 27” > <name origin=“Ukraine”> <first> Alexander </first> <middle> M. </middle> <last> Dekhtyar</last> </name> <dept> Computer Science </dept> <course> <sem> Spring 2007 </sem> <code> CS 405 </code> <title> Database systems </title> </course> </faculty>
XML and applications <? xml version=“ 1. 0”> <r> XML Files Parser Internal data structure API </r> documents data application
XML and applications <? xml version=“ 1. 0”> <r> XML Files Parser Internal data structure API </r> documents data application
XML and applications Document Object Model (DOM) § W 3 C standard § www. w 3 c. org/DOM Level 1 (core) – for XML DOME Level 1 (HTML) – for HTML Internal data structure API
Trees for XML faculty name dept course <faculty id =“ 27” > <name origin=“Ukraine”> <first> Alexander </first> <middle> M. </middle> <last> Dekhtyar</last> </name> <dept> Computer Science </dept> <course> <sem> Spring 2007 </sem> <code> CS 405 </code> <title> Database systems </title> </course> </faculty>
Trees for XML faculty Id=“ 27” first name middle dept course <faculty id =“ 27” > <name origin=“Ukraine”> <first> Alexander</first> <middle> M. </middle> <last> </last> Dekhtyar </name> <dept> Computer Science</dept> <course> <sem> Spring 2007 </sem> <code> CS 405 </code> <title> Database systems </title> </course> </faculty> sem last code title Computer Science Alexander origin=“Ukraine” M. Dekhtyar Spring 2007 CS 405 Database Systems
Trees for XML faculty Id=“ 27” first name dept middle course sem last <faculty id =“ 27” > <name origin=“Ukraine”> <first> Alexander</first> <middle> M. </middle> <last> </last> Dekhtyar </name> <dept> Computer Science</dept> <course> <sem> Spring 2007 </sem> <code> CS 405 </code> <title> Database systems </title> </course> </faculty> title code Computer Science Alexander M. Dekhtyar Spring 2007 CS 405 Database Systems origin=“Ukraine” name Computer Science - Element node - Text node faculty - Root node Id=“ 27” - Attribute node
Document Object Model / Abstract Data Type / Object-oriented / System of types/interfaces H Attributes H Methods
faculty Functionality Id=“ 27” first name middle dept course sem last code title Computer Science Alexander M. Dekhtyar Spring 2007 CS 405 origin=“Ukraine” Creation of nodes Insertion of nodes in into the DOM Tree Traversal of the DOM Tree Database Systems
DOM Type Structure list of interface Node s u b t y p e interface Node. List interface Document interface Element interface Attr interface Document. Type interface Comment interface Text interface Document. Type interface CDATASection … and a few more interface Named. Node. Map set of
interface Node DOMString node. Name DOMString node. Value short node. Type Node parent. Node. List child. Nodes Node first. Child Node last. Child Node previous. Sibling Node next. Sibling Named. Node. Map attributes Document owner. Document document faculty name first origin=“Ukraine” middle dept
Node Types node. Type interface Node s u b t y p e node. Name node. Value interface Document 9 interface Element 1 Tag interface Attr 2 Att. Name Att. Value interface Document. Type 10 interface Comment 8 interface Text 3 #text content interface Entity 6 interface CDATASection 4 … and a few more null (12 nodetypes altogether)
interface Node methods Node insert. Before(in Node new. Child, in Node ref. Child) insert. Before Node replace. Child(in Node new. Child, in Node old. Child) replace. Child Node remove. Child(in Node old. Child) remove. Child Node append. Child(in Node new. Child) append. Child boolean has. Child. Nodes() has. Child. Nodes Node clone. Node(in boolean deep) clone. Node
DOM Type Structure list of interface Node s u b t y p e interface Node. List interface Document interface Element interface Attr interface Document. Type interface Comment interface Text interface Document. Type interface CDATASection … and a few more interface Named. Node. Map set of
interface Document document e p y t c Attributes do Document. Type doctype Element document. Element root <a> Methods Element Document. Fragment Text Comment CDATASection Attr DTD <a> <a> create. Element(in DOMString tag. Name) create. Document. Fragment() create. Text. Node(in DOMString data) create. Comment(in DOMString data) create. CDATASection(in DOMString data) create. Attribute(in DOMString name) Node. List get. Elements. By. Tag. Name(in DOMString tagname)
DOM Type Structure list of interface Node s u b t y p e interface Node. List interface Document interface Element interface Attr interface Document. Type interface Comment interface Text interface Document. Type interface CDATASection … and a few more interface Named. Node. Map set of
interface Element : Node { DOMString tag. Name; Attribute management DOMString get. Attribute(in DOMString name); get. Attribute void set. Attribute(in DOMString name, in DOMString value) set. Attribute void remove. Attribute(in DOMString name) remove. Attribute Attr get. Attribute. Node(in DOMString name); get. Attribute. Node Attr set. Attribute. Node(in Attr new. Attr) set. Attribute. Node Attr remove. Attribute. Node(in Attr old. Attr) remove. Attribute. Node. List get. Elements. By. Tag. Name(in DOMString name) get. Elements. By. Tag. Name };
DOM Type Structure list of interface Node s u b t y p e interface Node. List interface Document interface Element interface Attr interface Document. Type interface Comment interface Text interface Document. Type interface CDATASection … and a few more interface Named. Node. Map set of
DOM Type Structure list of interface Node s u b t y p e interface Node. List interface Document interface Element interface Attr interface Document. Type interface Comment interface Text interface Document. Type interface CDATASection … and a few more interface Named. Node. Map set of
interface Node. List { Node item(in unsigned long index); item unsigned long length; length } interface Named. Node. Map { Node get. Named. Item(in DOMString name); get. Named. Item Node set. Named. Item(in Node arg); set. Named. Item Node remove. Named. Item(in DOMString name); Node item(in unsigned long index); item unsigned long length; length };
Next… Implementations of DOM interfaces nodes content attributes 1. Using pointers 3. Wrappers over legacy implementations 2. Using record arrays
- Slides: 26