Title: Document%20Object%20Model%20(DOM):%20%20An%20Abstract%20Data%20Structure%20for%20XML%20data
1Document Object Model (DOM) An Abstract Data
Structure for XML data
Department of Computer Science University of
Kentucky
2About
- Jobs for B.S. graduates often require work with
XML - Teach XML in undergraduate curriculum
- Databases
- Web Programming
- Data Structures
3Outline
- XML Syntax
- XML as a tree
- Document Object Model (DOM)
- DOM API
4XML
ltfacultygt ltnamegt ltfirstgt
lt/firstgt ltmiddlegt
lt/middlegt ltlastgt
lt/lastgt lt/namegt ltdeptgt
lt/deptgt ltcoursegt ltsemgt
lt/semgt ltcodegt
lt/codegt lttitlegt
lt/titlegt lt/coursegt lt/facultygt
Meta-language for encoding information
Alexander M.
Dekhtyar Computer Science Spring 2007
CS405 Database systems
Information, content
XML elements
Opening tags ltnamegt Closing tags ltname/gt Emply
elements ltp/gt
ordered
5XML
ltfaculty id 27 gt ltname
originUkrainegt ltfirstgt
lt/firstgt ltmiddlegt
lt/middlegt ltlastgt
lt/lastgt lt/namegt ltdeptgt
lt/deptgt ltcoursegt ltsemgt
lt/semgt ltcodegt
lt/codegt lttitlegt
lt/titlegt lt/coursegt lt/facultygt
Meta-language for encoding information
Alexander M.
Dekhtyar Computer Science Spring 2007
CS405 Database systems
Information, content
XML elements
Opening tags ltnamegt Closing tags ltname/gt Emply
elements ltp/gt
ordered
Attributes
Additional information unordered
6XML
ltfaculty id 27 gt ltname
originUkrainegt ltfirstgt
lt/firstgt ltmiddlegt
lt/middlegt ltlastgt
lt/lastgt lt/namegt ltdeptgt
lt/deptgt ltcoursegt ltsemgt
lt/semgt ltcodegt
lt/codegt lttitlegt
lt/titlegt lt/coursegt lt/facultygt
- Structure
- nested elements
- Well-formed XML
- correctly nested elements
- World Wide Web Consortium (W3C)
- recommendation
- XML 1.0, 1998
-
Alexander M.
Dekhtyar Computer Science Spring 2007
CS405 Database systems
7XML and applications
Parser
data
8XML and applications
Parser
data
application
9XML and applications
Document Object Model (DOM)
- W3C standard
- www.w3c.org/DOM
API
DOM Level 1 (core) for XML DOME Level 1 (HTML)
for HTML
10Trees for XML
faculty
dept
name
course
11Trees for XML
faculty
Id27
name
dept
course
title
code
sem
first
middle
last
Computer Science
Database Systems
Alexander
M.
Dekhtyar
Spring 2007
CS 405
originUkraine
12Trees for XML
- Root node
- Element node
faculty
name
Computer Science
- Text node
Id27
- Attribute node
13Document Object Model
- System of types/interfaces
14Functionality
Creation of nodes
Insertion of nodes in into the DOM Tree
Traversal of the DOM Tree
15DOM Type Structure
interface NodeList
list of
interface Node
interface Document
subtype
interface NamedNodeMap
interface Element
set of
interface Attr
interface DocumentType
interface Comment
interface Text
interface DocumentType
interface CDATASection
and a few more
16interface Node
document
faculty
DOMString nodeName DOMString nodeValue short
nodeType Node parentNode NodeList childNodes
Node firstChild Node lastChild Node
previousSibling Node nextSibling NamedNodeMap
attributes Document ownerDocument
name
dept
middle
first
originUkraine
17Node Types
nodeName
nodeValue
nodeType
interface Node
9 1 2 10 8 3 6 4
interface Document
subtype
interface Element
Tag null
interface Attr
AttName AttValue
interface DocumentType
interface Comment
text content
interface Text
interface Entity
interface CDATASection
and a few more
(12 nodetypes altogether)
18interface Node methods
Node insertBefore(in Node newChild, in Node
refChild) Node replaceChild(in Node newChild, in
Node oldChild) Node removeChild(in Node
oldChild) Node appendChild(in Node newChild)
boolean hasChildNodes() Node cloneNode(in
boolean deep)
19DOM Type Structure
interface NodeList
list of
interface Node
interface Document
subtype
interface NamedNodeMap
interface Element
set of
interface Attr
interface DocumentType
interface Comment
interface Text
interface DocumentType
interface CDATASection
and a few more
20interface Document
document
doctype
Attributes
root
DTD
ltagt
ltagt
ltagt
ltagt
Methods
Element createElement(in DOMString
tagName) DocumentFragment createDocumentFragment()
Text createTextNode(in DOMString
data) Comment createComment(in DOMString
data) CDATASection createCDATASection(in
DOMString data) Attr
createAttribute(in DOMString name) NodeList
getElementsByTagName(in DOMString tagname)
21DOM Type Structure
interface NodeList
list of
interface Node
interface Document
subtype
interface NamedNodeMap
interface Element
set of
interface Attr
interface DocumentType
interface Comment
interface Text
interface DocumentType
interface CDATASection
and a few more
22interface Element
interface Element Node DOMString tagName
DOMString getAttribute(in DOMString name)
void setAttribute(in DOMString name, in
DOMString value) void removeAttribute(in
DOMString name) Attr getAttributeNode(in
DOMString name) Attr setAttributeNode(in Attr
newAttr) Attr removeAttributeNode(in Attr
oldAttr) NodeList getElementsByTagName(in
DOMString name)
Attribute management
23DOM Type Structure
interface NodeList
list of
interface Node
interface Document
subtype
interface NamedNodeMap
interface Element
set of
interface Attr
interface DocumentType
interface Comment
interface Text
interface DocumentType
interface CDATASection
and a few more
24DOM Type Structure
interface NodeList
list of
interface Node
interface Document
subtype
interface NamedNodeMap
interface Element
set of
interface Attr
interface DocumentType
interface Comment
interface Text
interface DocumentType
interface CDATASection
and a few more
25interface NodeList
interface NodeList Node item(in unsigned
long index) unsigned long length
interface NamedNodeMap
interface NamedNodeMap Node getNamedItem(in
DOMString name) Node setNamedItem(in Node
arg) Node removeNamedItem(in DOMString name)
Node item(in unsigned long index)
unsigned long length
26Next
Implementations of DOM interfaces
1. Using pointers
3. Wrappers over legacy implementations