SlideShare una empresa de Scribd logo
1 de 25
MB
S

mbstechinfo@gmail.com
MB
S

Introduction
Introducing the DOM Objects

Working with the XML DOM
Validate and tranform an XML document

Exercises

Document Object Model

Sli
de
2
MB
S

Introducing the W3C DOM
 DOM Implementation


Document Object Model

Sli
de
3


XML Document Object Model (DOM)

MB
S

◦ W3C standard recommendation
◦ Build tree structure in memory for XML documents
◦ Provides an Application Programming Interface (API) for
dynamically accessing and manipulating a document
◦ DOM-based parsers parse these structures
 Exist in several languages (Java, C, C++, Python, Perl, etc.)

Document Object Model

Sli
de
4


Tree Structure of a Document:

MB
S

◦ Node is the basic building block of the DOM tree
structure.
◦ Nodes represent elements, attributes, content,
comments, etc.

Document Object Model

Sli
de
5
◦ Example
<?xml version = "1.0"?>
<message from = "Paul" to = "Tem">
<body>Hi, Tim!</body>
</message>

MB
S

 Node created for element message

 Element message has child node for body element
 Element body has child node for text "Hi, Tim!"
 Attributes from and to also have nodes in tree

Document Object Model

Sli
de
6
MB
S

The following figure represents how a DOM tree is used by applications to access data:

MSXML Library or other libraries
XML
Document

Parser
Parsed
Document

DOM Tree
Root
Child

Application
Text

Child
Text

Document Object Model

Sli
de
7


MB
S

DOM-based parsers
◦
◦
◦
◦
◦
◦
◦
◦
◦

Sun Microsystem’s JAXP
Apache Xerces
XML4J
DOM4J
JDOM
Microsoft’s msxml
4DOM
XML::DOM
…

Document Object Model

Sli
de
8
MB
S

Class/Interface

Description

Document interface

Represents the XML document’s top-level node, which provides
access to all the document’s nodes—including the root element.

Node interface

Represents an XML document node.

NodeList interface

Represents a read-only list of Node objects.

Element interface

Represents an element node. Derives from Node.

Attr interface

Represents an attribute node. Derives from Node.

CharacterData interface Represents character data. Derives from Node.
Text interface
Represents a text node. Derives from CharacterData.
Comment interface

Represents a comment node. Derives from CharacterData.

ProcessingInstruction
interface
CDATASection interface

Represents a processing instruction node. Derives from Node.
Represents a CDATA section. Derives from Text.

Document Object Model

Sli
de
9
Method Name

Description

createElement

Creates an element node.

createAttribute

Creates an attribute node.

createTextNode

Creates a text node.

createComment

MB
S

Creates a comment node.

createProcessingInstruction Creates a processing instruction node.
createCDATASection
Creates a CDATA section node.
getDocumentElement

Returns the document’s root element.

appendChild

Appends a child node.

getChildNodes

Returns the child nodes.

Document Object Model

Sli
de
10


MB
Following are the associated properties for the
S
Document object methods:
◦
◦
◦
◦
◦
◦

childNodes
documentElement
firstChild
lastChild
parseError
validateOnParse

Document Object Model

Sli
de
11
Method Name

Description

appendChild

Appends a child node.

cloneNode

Duplicates the node.

getAttributes Returns the node’s attributes.

MB
S

getChildNodes Returns the node’s child nodes.
getNodeName

Returns the node’s name.

getNodeType

Returns the node’s type (e.g., element, attribute,
text, etc.).

getNodeValue

Returns the node’s value.

getParentNode Returns the node’s parent.
hasChildNodes Returns true if the node has child nodes.
removeChild

Removes a child node from the node.

replaceChild

Replaces a child node with another node.

setNodeValue

Sets the node’s value.

insertBefore

Appends a child node in front of a child node.

Document Object Model

Sli
de
12


MB
Following are the associated properties Sthe
for
Node object methods:
◦
◦
◦
◦
◦
◦
◦

nodeName
nodeType
nodeValue
childNodes
firstChild
lastChild
text

Document Object Model

Sli
de
13
MB
S

Node Type

Description

Node.ELEMENT_NODE

Represents an element node.

Node.ATTRIBUTE_NODE

Represents an attribute node.

Node.TEXT_NODE

Represents a text node.

Node.COMMENT_NODE

Represents a comment node.

Node.PROCESSING_INSTRUCTION_NODE

Represents a processing instruction node.

Node.CDATA_SECTION_NODE

Represents a CDATA section node.

Document Object Model

Sli
de
14
MB
S
Method Name

Description

getAttribute

Returns an attribute’s value.

getTagName

Returns an element’s name.

removeAttribute

Removes an element’s attribute.

setAttribute

Sets an attribute’s value.

Document Object Model

Sli
de
15
MB
S

<?xml version="1.0"?>
<article>
<title>XML Demo</title>
<date>August 22, 2007</date>
<author>
<fname>Nguyen Van</fname>
<lname>Teo</lname>
</author>
<summary>XML is pretty easy.</summary>
<content>Once you have mastered HTML, XML is
easily
learned. You must remember that XML is not for
displaying information but for managing
information.
</content>
</article>

Document Object Model

Sli
de
16
MB
S

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>A DOM Example</title>
</head>
<body>

Element script allows for
including scripting code

<script type = "text/javascript" language
"JavaScript">

Instantiate
Microsoft XML
=
DOM object

var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.load("article.xml");
Load article.xml into memory;
var

msxml parses article.xml and
element=xmlDoc.documentElement; stores it as tree structure

Document Object Model

Sli
de
17
Assign article as root element
var element=xmlDoc.documentElement;// get the root element
document.writeln(
"<p>Here is the root node of the document:" );
document.writeln( "<strong>" + element.nodeName
+ "</strong>" );

MB
S

Place root element’s name in element
strong and write it to browser

document.writeln(
"<br>The following are its child elements:" );
document.writeln( "</p><ul>" );

// traverse all child nodes of root element
for ( i = 0; i < element.childNodes.length; i++ ) {
var curNode = element.childNodes.item(i);

}

// print node name of each child element
document.writeln( "<li><strong>" + curNode.nodeName
+ "</strong></li>" );

Assign index to each
child node of root node

document.writeln( "</ul>" );
// get the first child node of root element
var currentNode = element.firstChild;

Retrieve root node’s first
child node (title)
Document Object Model

Sli
de
18
MB
S

Siblings are nodes at same level in

document.writeln( "<p>The first child of root node is:" );
document (e.g., title, date,
document.writeln( "<strong>" + currentNode.nodeName
+ "</strong>" );
author, summary and content)
document.writeln( "<br>whose next sibling is:" );
// get the next sibling of first child
var nextSib = currentNode.nextSibling;
document.writeln( "<strong>" + nextSib.nodeName
+ "</strong>." );
Get first child’s next sibling (date)
document.writeln( "<br>Value of <strong>" + nextSib.nodeName
+ "</strong> element is:" );
var value = nextSib.firstChild;

Get first child of date

// print the text value of the sibling
document.writeln( "<em>" + value.nodeValue + "</em>" );
document.writeln( "<br>Parent node of " );
document.writeln( "<strong>" + nextSib.nodeName
+ "</strong> is:" );
document.writeln( "<strong>" + nextSib.parentNode.nodeName
+ "</strong>.</p>" );
</script>
</body>
</html>

Get parent of date (article)

Document Object Model

Sli
de
19
MB
S

Document Object Model

Sli
de
20
Validate XML document with DTD
 Read XML document


Document Object Model

MB
S

Sli
de
21


MB
S

To be continued…

Document Object Model

Sli
de
22
MB
S

XML How to program
 http://www.w3.org
 XML tutorial http://www.w3schools.com/w3c/


Document Object Model

Sli
de
23
MB
S

Feel free to post questions at
http://yht4ever.blogspot.com
 or email to:
thanh.phamhong@niithoasen.com or
thanh.phamhong@niit-vn.com


Document Object Model

Sli
de
24
MB
S

mbstechinfo@gmail.com

Más contenido relacionado

La actualidad más candente

Dom(document object model)
Dom(document object model)Dom(document object model)
Dom(document object model)Partnered Health
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Modelchomas kandar
 
JavaScript DOM & event
JavaScript DOM & eventJavaScript DOM & event
JavaScript DOM & eventBorey Lim
 
The Document Object Model
The Document Object ModelThe Document Object Model
The Document Object ModelKhou Suylong
 
introduction to the document object model- Dom chapter5
introduction to the document object model- Dom chapter5introduction to the document object model- Dom chapter5
introduction to the document object model- Dom chapter5FLYMAN TECHNOLOGY LIMITED
 
An Introduction to the DOM
An Introduction to the DOMAn Introduction to the DOM
An Introduction to the DOMMindy McAdams
 
Dom Hackking & Security - BlackHat Preso
Dom Hackking & Security - BlackHat PresoDom Hackking & Security - BlackHat Preso
Dom Hackking & Security - BlackHat PresoShreeraj Shah
 
Document Object Model
Document Object ModelDocument Object Model
Document Object ModelMayur Mudgal
 
Internet and Web Technology (CLASS-7) [XML and AJAX] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-7) [XML and AJAX] | NIC/NIELIT Web TechnologyInternet and Web Technology (CLASS-7) [XML and AJAX] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-7) [XML and AJAX] | NIC/NIELIT Web TechnologyAyes Chinmay
 
Xml part 6
Xml part 6Xml part 6
Xml part 6NOHA AW
 

La actualidad más candente (18)

Dom(document object model)
Dom(document object model)Dom(document object model)
Dom(document object model)
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Model
 
JavaScript DOM & event
JavaScript DOM & eventJavaScript DOM & event
JavaScript DOM & event
 
The Document Object Model
The Document Object ModelThe Document Object Model
The Document Object Model
 
Xml dom
Xml domXml dom
Xml dom
 
Dom parser
Dom parserDom parser
Dom parser
 
DOM and SAX
DOM and SAXDOM and SAX
DOM and SAX
 
Dom
DomDom
Dom
 
introduction to the document object model- Dom chapter5
introduction to the document object model- Dom chapter5introduction to the document object model- Dom chapter5
introduction to the document object model- Dom chapter5
 
DOM-XML
DOM-XMLDOM-XML
DOM-XML
 
Xml Lecture Notes
Xml Lecture NotesXml Lecture Notes
Xml Lecture Notes
 
An Introduction to the DOM
An Introduction to the DOMAn Introduction to the DOM
An Introduction to the DOM
 
Dom Hackking & Security - BlackHat Preso
Dom Hackking & Security - BlackHat PresoDom Hackking & Security - BlackHat Preso
Dom Hackking & Security - BlackHat Preso
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Model
 
JavaScript and DOM
JavaScript and DOMJavaScript and DOM
JavaScript and DOM
 
Internet and Web Technology (CLASS-7) [XML and AJAX] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-7) [XML and AJAX] | NIC/NIELIT Web TechnologyInternet and Web Technology (CLASS-7) [XML and AJAX] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-7) [XML and AJAX] | NIC/NIELIT Web Technology
 
Xml part 6
Xml part 6Xml part 6
Xml part 6
 
Unit 4(it workshop)
Unit 4(it workshop)Unit 4(it workshop)
Unit 4(it workshop)
 

Destacado (15)

24sax
24sax24sax
24sax
 
Xml & Java
Xml & JavaXml & Java
Xml & Java
 
XML
XMLXML
XML
 
Simple API for XML
Simple API for XMLSimple API for XML
Simple API for XML
 
XML
XMLXML
XML
 
RESTful services with JAXB and JPA
RESTful services with JAXB and JPARESTful services with JAXB and JPA
RESTful services with JAXB and JPA
 
SAX, DOM & JDOM parsers for beginners
SAX, DOM & JDOM parsers for beginnersSAX, DOM & JDOM parsers for beginners
SAX, DOM & JDOM parsers for beginners
 
6 xml parsing
6   xml parsing6   xml parsing
6 xml parsing
 
WEB PROGRAMMING UNIT IV NOTES BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT IV NOTES BY BHAVSINGH MALOTHWEB PROGRAMMING UNIT IV NOTES BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT IV NOTES BY BHAVSINGH MALOTH
 
Session 5
Session 5Session 5
Session 5
 
XML parsing using jaxb
XML parsing using jaxbXML parsing using jaxb
XML parsing using jaxb
 
SAX (con PHP)
SAX (con PHP)SAX (con PHP)
SAX (con PHP)
 
XML SAX PARSING
XML SAX PARSING XML SAX PARSING
XML SAX PARSING
 
Xml parsers
Xml parsersXml parsers
Xml parsers
 
Java XML Parsing
Java XML ParsingJava XML Parsing
Java XML Parsing
 

Similar a Xml dom & sax by bhavsingh maloth

Document object model
Document object modelDocument object model
Document object modelAmit kumar
 
12. session 12 java script objects
12. session 12   java script objects12. session 12   java script objects
12. session 12 java script objectsPhúc Đỗ
 
Web Performance Tips
Web Performance TipsWeb Performance Tips
Web Performance TipsRavi Raj
 
Pyconie 2012
Pyconie 2012Pyconie 2012
Pyconie 2012Yaqi Zhao
 
Web2py tutorial to create db driven application.
Web2py tutorial to create db driven application.Web2py tutorial to create db driven application.
Web2py tutorial to create db driven application.fRui Apps
 
04 sm3 xml_xp_07
04 sm3 xml_xp_0704 sm3 xml_xp_07
04 sm3 xml_xp_07Niit Care
 
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...Bill Buchan
 
java API for XML DOM
java API for XML DOMjava API for XML DOM
java API for XML DOMSurinder Kaur
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to JavascriptSeble Nigussie
 
Entity Framework Database and Code First
Entity Framework Database and Code FirstEntity Framework Database and Code First
Entity Framework Database and Code FirstJames Johnson
 

Similar a Xml dom & sax by bhavsingh maloth (20)

6867389.ppt
6867389.ppt6867389.ppt
6867389.ppt
 
6867389.ppt
6867389.ppt6867389.ppt
6867389.ppt
 
6867389 (1).ppt
6867389 (1).ppt6867389 (1).ppt
6867389 (1).ppt
 
Javascript.ppt
Javascript.pptJavascript.ppt
Javascript.ppt
 
Dom structure
Dom structure Dom structure
Dom structure
 
Document object model
Document object modelDocument object model
Document object model
 
DOM and Events
DOM and EventsDOM and Events
DOM and Events
 
12. session 12 java script objects
12. session 12   java script objects12. session 12   java script objects
12. session 12 java script objects
 
Web Performance Tips
Web Performance TipsWeb Performance Tips
Web Performance Tips
 
Mongo learning series
Mongo learning series Mongo learning series
Mongo learning series
 
Pyconie 2012
Pyconie 2012Pyconie 2012
Pyconie 2012
 
Automating Ievb
Automating IevbAutomating Ievb
Automating Ievb
 
Web2py tutorial to create db driven application.
Web2py tutorial to create db driven application.Web2py tutorial to create db driven application.
Web2py tutorial to create db driven application.
 
Java script
Java scriptJava script
Java script
 
04 sm3 xml_xp_07
04 sm3 xml_xp_0704 sm3 xml_xp_07
04 sm3 xml_xp_07
 
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...
Lotusphere 2007 AD507 Leveraging the Power of Object Oriented Programming in ...
 
java API for XML DOM
java API for XML DOMjava API for XML DOM
java API for XML DOM
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
La sql
La sqlLa sql
La sql
 
Entity Framework Database and Code First
Entity Framework Database and Code FirstEntity Framework Database and Code First
Entity Framework Database and Code First
 

Más de Bhavsingh Maloth

web programming Unit VI PPT by Bhavsingh Maloth
web programming Unit VI PPT  by Bhavsingh Malothweb programming Unit VI PPT  by Bhavsingh Maloth
web programming Unit VI PPT by Bhavsingh MalothBhavsingh Maloth
 
web programming Unit VIII complete about python by Bhavsingh Maloth
web programming Unit VIII complete about python  by Bhavsingh Malothweb programming Unit VIII complete about python  by Bhavsingh Maloth
web programming Unit VIII complete about python by Bhavsingh MalothBhavsingh Maloth
 
web programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh Malothweb programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh MalothBhavsingh Maloth
 
Web programming unit IIII XML &DOM NOTES BY BHAVSINGH MALOTH
Web programming unit IIII XML &DOM NOTES BY BHAVSINGH MALOTHWeb programming unit IIII XML &DOM NOTES BY BHAVSINGH MALOTH
Web programming unit IIII XML &DOM NOTES BY BHAVSINGH MALOTHBhavsingh Maloth
 
WEB PROGRAMMING UNIT VIII BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VIII BY BHAVSINGH MALOTHWEB PROGRAMMING UNIT VIII BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VIII BY BHAVSINGH MALOTHBhavsingh Maloth
 
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTHWEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTHBhavsingh Maloth
 
WEB PROGRAMMING UNIT V BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT V BY BHAVSINGH MALOTHWEB PROGRAMMING UNIT V BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT V BY BHAVSINGH MALOTHBhavsingh Maloth
 
WEB PROGRAMMING UNIT II BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT II BY BHAVSINGH MALOTHWEB PROGRAMMING UNIT II BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT II BY BHAVSINGH MALOTHBhavsingh Maloth
 
Web programming UNIT II by Bhavsingh Maloth
Web programming UNIT II by Bhavsingh MalothWeb programming UNIT II by Bhavsingh Maloth
Web programming UNIT II by Bhavsingh MalothBhavsingh Maloth
 
Appscpolytechniclecturersg.s.paper2007
Appscpolytechniclecturersg.s.paper2007Appscpolytechniclecturersg.s.paper2007
Appscpolytechniclecturersg.s.paper2007Bhavsingh Maloth
 
Appscpolytechniclecturersg.s.paper2007
Appscpolytechniclecturersg.s.paper2007Appscpolytechniclecturersg.s.paper2007
Appscpolytechniclecturersg.s.paper2007Bhavsingh Maloth
 
98286173 government-polytechnic-lecturer-exam-paper-2012
98286173 government-polytechnic-lecturer-exam-paper-201298286173 government-polytechnic-lecturer-exam-paper-2012
98286173 government-polytechnic-lecturer-exam-paper-2012Bhavsingh Maloth
 
Web Programming UNIT VIII notes
Web Programming UNIT VIII notesWeb Programming UNIT VIII notes
Web Programming UNIT VIII notesBhavsingh Maloth
 

Más de Bhavsingh Maloth (20)

web programming Unit VI PPT by Bhavsingh Maloth
web programming Unit VI PPT  by Bhavsingh Malothweb programming Unit VI PPT  by Bhavsingh Maloth
web programming Unit VI PPT by Bhavsingh Maloth
 
web programming Unit VIII complete about python by Bhavsingh Maloth
web programming Unit VIII complete about python  by Bhavsingh Malothweb programming Unit VIII complete about python  by Bhavsingh Maloth
web programming Unit VIII complete about python by Bhavsingh Maloth
 
web programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh Malothweb programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh Maloth
 
Web programming unit IIII XML &DOM NOTES BY BHAVSINGH MALOTH
Web programming unit IIII XML &DOM NOTES BY BHAVSINGH MALOTHWeb programming unit IIII XML &DOM NOTES BY BHAVSINGH MALOTH
Web programming unit IIII XML &DOM NOTES BY BHAVSINGH MALOTH
 
WEB PROGRAMMING UNIT VIII BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VIII BY BHAVSINGH MALOTHWEB PROGRAMMING UNIT VIII BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VIII BY BHAVSINGH MALOTH
 
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTHWEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
 
WEB PROGRAMMING UNIT V BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT V BY BHAVSINGH MALOTHWEB PROGRAMMING UNIT V BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT V BY BHAVSINGH MALOTH
 
WEB PROGRAMMING UNIT II BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT II BY BHAVSINGH MALOTHWEB PROGRAMMING UNIT II BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT II BY BHAVSINGH MALOTH
 
Web programming UNIT II by Bhavsingh Maloth
Web programming UNIT II by Bhavsingh MalothWeb programming UNIT II by Bhavsingh Maloth
Web programming UNIT II by Bhavsingh Maloth
 
Polytechnic jan 6 2012
Polytechnic jan 6 2012Polytechnic jan 6 2012
Polytechnic jan 6 2012
 
Appscpolytechniclecturersg.s.paper2007
Appscpolytechniclecturersg.s.paper2007Appscpolytechniclecturersg.s.paper2007
Appscpolytechniclecturersg.s.paper2007
 
Appsc poly key 2013
Appsc poly key 2013Appsc poly key 2013
Appsc poly key 2013
 
Appscpolytechniclecturersg.s.paper2007
Appscpolytechniclecturersg.s.paper2007Appscpolytechniclecturersg.s.paper2007
Appscpolytechniclecturersg.s.paper2007
 
Appsc poly key 2013
Appsc poly key 2013Appsc poly key 2013
Appsc poly key 2013
 
98286173 government-polytechnic-lecturer-exam-paper-2012
98286173 government-polytechnic-lecturer-exam-paper-201298286173 government-polytechnic-lecturer-exam-paper-2012
98286173 government-polytechnic-lecturer-exam-paper-2012
 
Unit vii wp ppt
Unit vii wp pptUnit vii wp ppt
Unit vii wp ppt
 
Unit VI
Unit VI Unit VI
Unit VI
 
Wp unit III
Wp unit IIIWp unit III
Wp unit III
 
Web Programming UNIT VIII notes
Web Programming UNIT VIII notesWeb Programming UNIT VIII notes
Web Programming UNIT VIII notes
 
Wp unit 1 (1)
Wp  unit 1 (1)Wp  unit 1 (1)
Wp unit 1 (1)
 

Último

Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 

Último (20)

Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 

Xml dom & sax by bhavsingh maloth

  • 2. MB S Introduction Introducing the DOM Objects Working with the XML DOM Validate and tranform an XML document Exercises Document Object Model Sli de 2
  • 3. MB S Introducing the W3C DOM  DOM Implementation  Document Object Model Sli de 3
  • 4.  XML Document Object Model (DOM) MB S ◦ W3C standard recommendation ◦ Build tree structure in memory for XML documents ◦ Provides an Application Programming Interface (API) for dynamically accessing and manipulating a document ◦ DOM-based parsers parse these structures  Exist in several languages (Java, C, C++, Python, Perl, etc.) Document Object Model Sli de 4
  • 5.  Tree Structure of a Document: MB S ◦ Node is the basic building block of the DOM tree structure. ◦ Nodes represent elements, attributes, content, comments, etc. Document Object Model Sli de 5
  • 6. ◦ Example <?xml version = "1.0"?> <message from = "Paul" to = "Tem"> <body>Hi, Tim!</body> </message> MB S  Node created for element message  Element message has child node for body element  Element body has child node for text "Hi, Tim!"  Attributes from and to also have nodes in tree Document Object Model Sli de 6
  • 7. MB S The following figure represents how a DOM tree is used by applications to access data: MSXML Library or other libraries XML Document Parser Parsed Document DOM Tree Root Child Application Text Child Text Document Object Model Sli de 7
  • 8.  MB S DOM-based parsers ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ ◦ Sun Microsystem’s JAXP Apache Xerces XML4J DOM4J JDOM Microsoft’s msxml 4DOM XML::DOM … Document Object Model Sli de 8
  • 9. MB S Class/Interface Description Document interface Represents the XML document’s top-level node, which provides access to all the document’s nodes—including the root element. Node interface Represents an XML document node. NodeList interface Represents a read-only list of Node objects. Element interface Represents an element node. Derives from Node. Attr interface Represents an attribute node. Derives from Node. CharacterData interface Represents character data. Derives from Node. Text interface Represents a text node. Derives from CharacterData. Comment interface Represents a comment node. Derives from CharacterData. ProcessingInstruction interface CDATASection interface Represents a processing instruction node. Derives from Node. Represents a CDATA section. Derives from Text. Document Object Model Sli de 9
  • 10. Method Name Description createElement Creates an element node. createAttribute Creates an attribute node. createTextNode Creates a text node. createComment MB S Creates a comment node. createProcessingInstruction Creates a processing instruction node. createCDATASection Creates a CDATA section node. getDocumentElement Returns the document’s root element. appendChild Appends a child node. getChildNodes Returns the child nodes. Document Object Model Sli de 10
  • 11.  MB Following are the associated properties for the S Document object methods: ◦ ◦ ◦ ◦ ◦ ◦ childNodes documentElement firstChild lastChild parseError validateOnParse Document Object Model Sli de 11
  • 12. Method Name Description appendChild Appends a child node. cloneNode Duplicates the node. getAttributes Returns the node’s attributes. MB S getChildNodes Returns the node’s child nodes. getNodeName Returns the node’s name. getNodeType Returns the node’s type (e.g., element, attribute, text, etc.). getNodeValue Returns the node’s value. getParentNode Returns the node’s parent. hasChildNodes Returns true if the node has child nodes. removeChild Removes a child node from the node. replaceChild Replaces a child node with another node. setNodeValue Sets the node’s value. insertBefore Appends a child node in front of a child node. Document Object Model Sli de 12
  • 13.  MB Following are the associated properties Sthe for Node object methods: ◦ ◦ ◦ ◦ ◦ ◦ ◦ nodeName nodeType nodeValue childNodes firstChild lastChild text Document Object Model Sli de 13
  • 14. MB S Node Type Description Node.ELEMENT_NODE Represents an element node. Node.ATTRIBUTE_NODE Represents an attribute node. Node.TEXT_NODE Represents a text node. Node.COMMENT_NODE Represents a comment node. Node.PROCESSING_INSTRUCTION_NODE Represents a processing instruction node. Node.CDATA_SECTION_NODE Represents a CDATA section node. Document Object Model Sli de 14
  • 15. MB S Method Name Description getAttribute Returns an attribute’s value. getTagName Returns an element’s name. removeAttribute Removes an element’s attribute. setAttribute Sets an attribute’s value. Document Object Model Sli de 15
  • 16. MB S <?xml version="1.0"?> <article> <title>XML Demo</title> <date>August 22, 2007</date> <author> <fname>Nguyen Van</fname> <lname>Teo</lname> </author> <summary>XML is pretty easy.</summary> <content>Once you have mastered HTML, XML is easily learned. You must remember that XML is not for displaying information but for managing information. </content> </article> Document Object Model Sli de 16
  • 17. MB S <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>A DOM Example</title> </head> <body> Element script allows for including scripting code <script type = "text/javascript" language "JavaScript"> Instantiate Microsoft XML = DOM object var xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.load("article.xml"); Load article.xml into memory; var msxml parses article.xml and element=xmlDoc.documentElement; stores it as tree structure Document Object Model Sli de 17
  • 18. Assign article as root element var element=xmlDoc.documentElement;// get the root element document.writeln( "<p>Here is the root node of the document:" ); document.writeln( "<strong>" + element.nodeName + "</strong>" ); MB S Place root element’s name in element strong and write it to browser document.writeln( "<br>The following are its child elements:" ); document.writeln( "</p><ul>" ); // traverse all child nodes of root element for ( i = 0; i < element.childNodes.length; i++ ) { var curNode = element.childNodes.item(i); } // print node name of each child element document.writeln( "<li><strong>" + curNode.nodeName + "</strong></li>" ); Assign index to each child node of root node document.writeln( "</ul>" ); // get the first child node of root element var currentNode = element.firstChild; Retrieve root node’s first child node (title) Document Object Model Sli de 18
  • 19. MB S Siblings are nodes at same level in document.writeln( "<p>The first child of root node is:" ); document (e.g., title, date, document.writeln( "<strong>" + currentNode.nodeName + "</strong>" ); author, summary and content) document.writeln( "<br>whose next sibling is:" ); // get the next sibling of first child var nextSib = currentNode.nextSibling; document.writeln( "<strong>" + nextSib.nodeName + "</strong>." ); Get first child’s next sibling (date) document.writeln( "<br>Value of <strong>" + nextSib.nodeName + "</strong> element is:" ); var value = nextSib.firstChild; Get first child of date // print the text value of the sibling document.writeln( "<em>" + value.nodeValue + "</em>" ); document.writeln( "<br>Parent node of " ); document.writeln( "<strong>" + nextSib.nodeName + "</strong> is:" ); document.writeln( "<strong>" + nextSib.parentNode.nodeName + "</strong>.</p>" ); </script> </body> </html> Get parent of date (article) Document Object Model Sli de 19
  • 21. Validate XML document with DTD  Read XML document  Document Object Model MB S Sli de 21
  • 22.  MB S To be continued… Document Object Model Sli de 22
  • 23. MB S XML How to program  http://www.w3.org  XML tutorial http://www.w3schools.com/w3c/  Document Object Model Sli de 23
  • 24. MB S Feel free to post questions at http://yht4ever.blogspot.com  or email to: thanh.phamhong@niithoasen.com or thanh.phamhong@niit-vn.com  Document Object Model Sli de 24