SlideShare a Scribd company logo
1 of 19
DOM Parser
By
Sana Mateen
DOM
• The Document Object Model is an official recommendation of the
World Wide Web Consortium (W3C). It defines an interface that
enables programs to access and update the style, structure,and
contents of XML documents. XML parsers that support the DOM
implement that interface.
• When to use?
• You should use a DOM parser when:
• You need to know a lot about the structure of a document
• You need to move parts of the document around (you might want to
sort certain elements, for example)
• You need to use the information in the document more than once
• What you get?
• When you parse an XML document with a DOM parser, you get
back a tree structure that contains all of the elements of your
document. The DOM provides a variety of functions you can use to
examine the contents and structure of the document.
Common DOM methods
• When you are working with the DOM, there are several methods you'll use
often:
• Document.getDocumentElement() - Returns the root element of the
document.
• Node.getFirstChild() - Returns the first child of a given Node.
• Node.getLastChild() - Returns the last child of a given Node.
• Node.getNextSibling() - These methods return the next sibling of a given
Node.
• Node.getPreviousSibling() - These methods return the previous sibling of
a given Node.
• Node.getAttribute(attrName) - For a given Node, returns the attribute
with the requested name.
Steps to Using DOM
• Following are the steps used while parsing a document using DOM Parser.
• Import XML-related packages.
• Create a DocumentBuilder
• Create a Document from a file or stream
• Extract the root element
• Examine attributes
• Examine sub-elements
• Import XML-related packages
• import org.w3c.dom.*;
• import javax.xml.parsers.*;
• import java.io.*;
• Create a DocumentBuilder
• DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
• DocumentBuilder builder = factory.newDocumentBuilder();
• Create a Document from a file or stream
• StringBuilder xmlStringBuilder = new StringBuilder(); xmlStringBuilder.append("<?xml
version="1.0"?> <class> </class>"); ByteArrayInputStream input = new
ByteArrayInputStream( xmlStringBuilder.toString().getBytes("UTF-8"));
• Document doc = builder.parse(input);
• Extract the root element
• Element root = document.getDocumentElement();
• Examine attributes
• //returns specific attribute
• getAttribute("attributeName");
• //returns a (table) of names/values
• getAttributes();
• Examine sub-elements
• //returns a list of subelements of specified name
getElementsByTagName("subelementName"); /
• /returns a list of all child nodes
• getChildNodes();
SAX PARSER
•SAX (the Simple API for XML) is an event-based parser for xml
documents.
• Unlike a DOM parser, a SAX parser creates no parse tree. SAX is a
streaming interface for XML, which means that applications using SAX receive
event notifications about the XML document being processed an element, and
attribute, at a time in sequential order starting at the top of the document, and
ending with the closing of the ROOT element.
SAX
• Reads an XML document from top to bottom, recognizing the tokens that
make up a well-formed XML document
• Tokens are processed in the same order that they appear in the document
• Reports the application program the nature of tokens that the parser has
encountered as they occur
• The application program provides an "event" handler that must be
registered with the parser
• As the tokens are identified, callback methods in the handler are invoked
with the relevant information
When to use?
• You should use a SAX parser when:
• You can process the XML document in a linear fashion from the top down
• The document is not deeply nested
• You are processing a very large XML document whose DOM tree would
consume too much memory.Typical DOM implementations use ten bytes of
memory to represent one byte of XML
• The problem to be solved involves only part of the XML document
• Data is available as soon as it is seen by the parser, so SAX works well for
an XML document that arrives over a stream
• Disadvantages of SAX
• We have no random access to an XML document since it is processed in a
forward-only manner
• If you need to keep track of data the parser has seen or change the order of
items, you must write the code and store the data on your own
Dom parser
Dom parser
Dom parser
Dom parser
Dom parser

More Related Content

What's hot

Advanced Python : Static and Class Methods
Advanced Python : Static and Class Methods Advanced Python : Static and Class Methods
Advanced Python : Static and Class Methods Bhanwar Singh Meena
 
Static keyword ppt
Static keyword pptStatic keyword ppt
Static keyword pptVinod Kumar
 
Protection and Security in Operating Systems
Protection and Security in Operating SystemsProtection and Security in Operating Systems
Protection and Security in Operating Systemsvampugani
 
Codd's rules
Codd's rulesCodd's rules
Codd's rulesMohd Arif
 
Lecture 01 introduction to database
Lecture 01 introduction to databaseLecture 01 introduction to database
Lecture 01 introduction to databaseemailharmeet
 
Introduction to Bootstrap: Design for Developers
Introduction to Bootstrap: Design for DevelopersIntroduction to Bootstrap: Design for Developers
Introduction to Bootstrap: Design for DevelopersMelvin John
 
Web apps architecture
Web apps architectureWeb apps architecture
Web apps architectureTanmoy Barman
 
ASP.NET 07 - Site Navigation
ASP.NET 07 - Site NavigationASP.NET 07 - Site Navigation
ASP.NET 07 - Site NavigationRandy Connolly
 
graphics programming in java
graphics programming in javagraphics programming in java
graphics programming in javaAbinaya B
 
JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events WebStackAcademy
 
Indexing and Hashing
Indexing and HashingIndexing and Hashing
Indexing and Hashingsathish sak
 
Object Modeling Techniques
Object Modeling TechniquesObject Modeling Techniques
Object Modeling TechniquesShilpa Wadhwani
 

What's hot (20)

Ooad unit – 1 introduction
Ooad unit – 1 introductionOoad unit – 1 introduction
Ooad unit – 1 introduction
 
Dynamic HTML (DHTML)
Dynamic HTML (DHTML)Dynamic HTML (DHTML)
Dynamic HTML (DHTML)
 
Xml parsers
Xml parsersXml parsers
Xml parsers
 
Advanced Python : Static and Class Methods
Advanced Python : Static and Class Methods Advanced Python : Static and Class Methods
Advanced Python : Static and Class Methods
 
Static keyword ppt
Static keyword pptStatic keyword ppt
Static keyword ppt
 
Wrapper class
Wrapper classWrapper class
Wrapper class
 
Protection and Security in Operating Systems
Protection and Security in Operating SystemsProtection and Security in Operating Systems
Protection and Security in Operating Systems
 
Codd's rules
Codd's rulesCodd's rules
Codd's rules
 
Lecture 01 introduction to database
Lecture 01 introduction to databaseLecture 01 introduction to database
Lecture 01 introduction to database
 
Xml schema
Xml schemaXml schema
Xml schema
 
Xml databases
Xml databasesXml databases
Xml databases
 
Introduction to Bootstrap: Design for Developers
Introduction to Bootstrap: Design for DevelopersIntroduction to Bootstrap: Design for Developers
Introduction to Bootstrap: Design for Developers
 
Web apps architecture
Web apps architectureWeb apps architecture
Web apps architecture
 
ASP.NET 07 - Site Navigation
ASP.NET 07 - Site NavigationASP.NET 07 - Site Navigation
ASP.NET 07 - Site Navigation
 
graphics programming in java
graphics programming in javagraphics programming in java
graphics programming in java
 
JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events
 
Css ppt
Css pptCss ppt
Css ppt
 
Indexing and Hashing
Indexing and HashingIndexing and Hashing
Indexing and Hashing
 
UML Modeling in Java
UML Modeling in JavaUML Modeling in Java
UML Modeling in Java
 
Object Modeling Techniques
Object Modeling TechniquesObject Modeling Techniques
Object Modeling Techniques
 

Viewers also liked

Using cookies and sessions
Using cookies and sessionsUsing cookies and sessions
Using cookies and sessionsNuha Noor
 
Understanding layout managers
Understanding layout managersUnderstanding layout managers
Understanding layout managersNuha Noor
 
Jdbc in servlets
Jdbc in servletsJdbc in servlets
Jdbc in servletsNuha Noor
 
Quiz app(j tabbed pane,jdialog,container,actionevent,jradiobutton,buttongroup...
Quiz app(j tabbed pane,jdialog,container,actionevent,jradiobutton,buttongroup...Quiz app(j tabbed pane,jdialog,container,actionevent,jradiobutton,buttongroup...
Quiz app(j tabbed pane,jdialog,container,actionevent,jradiobutton,buttongroup...Nuha Noor
 
Http request and http response
Http request and http responseHttp request and http response
Http request and http responseNuha Noor
 
Jsp elements
Jsp elementsJsp elements
Jsp elementsNuha Noor
 
Reading init param
Reading init paramReading init param
Reading init paramNuha Noor
 

Viewers also liked (13)

Using cookies and sessions
Using cookies and sessionsUsing cookies and sessions
Using cookies and sessions
 
Understanding layout managers
Understanding layout managersUnderstanding layout managers
Understanding layout managers
 
Jdbc in servlets
Jdbc in servletsJdbc in servlets
Jdbc in servlets
 
Events1
Events1Events1
Events1
 
Intro xml
Intro xmlIntro xml
Intro xml
 
Xhtml
XhtmlXhtml
Xhtml
 
Xml dom
Xml domXml dom
Xml dom
 
Xml dtd
Xml dtdXml dtd
Xml dtd
 
Quiz app(j tabbed pane,jdialog,container,actionevent,jradiobutton,buttongroup...
Quiz app(j tabbed pane,jdialog,container,actionevent,jradiobutton,buttongroup...Quiz app(j tabbed pane,jdialog,container,actionevent,jradiobutton,buttongroup...
Quiz app(j tabbed pane,jdialog,container,actionevent,jradiobutton,buttongroup...
 
Xml schema
Xml schemaXml schema
Xml schema
 
Http request and http response
Http request and http responseHttp request and http response
Http request and http response
 
Jsp elements
Jsp elementsJsp elements
Jsp elements
 
Reading init param
Reading init paramReading init param
Reading init param
 

Similar to Dom parser (20)

Unit iv xml dom
Unit iv xml domUnit iv xml dom
Unit iv xml dom
 
Unit 2
Unit 2 Unit 2
Unit 2
 
Jdom how it works & how it opened the java process
Jdom how it works & how it opened the java processJdom how it works & how it opened the java process
Jdom how it works & how it opened the java process
 
Xml parsing
Xml parsingXml parsing
Xml parsing
 
DOM-XML
DOM-XMLDOM-XML
DOM-XML
 
XML
XMLXML
XML
 
25dom
25dom25dom
25dom
 
XMl
XMlXMl
XMl
 
Data interchange integration, HTML XML Biological XML DTD
Data interchange integration, HTML XML Biological XML DTDData interchange integration, HTML XML Biological XML DTD
Data interchange integration, HTML XML Biological XML DTD
 
Advanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojoAdvanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojo
 
XML
XMLXML
XML
 
WEB TECHNOLOGY Unit-4.pptx
WEB TECHNOLOGY Unit-4.pptxWEB TECHNOLOGY Unit-4.pptx
WEB TECHNOLOGY Unit-4.pptx
 
Solr Recipes Workshop
Solr Recipes WorkshopSolr Recipes Workshop
Solr Recipes Workshop
 
Xml
XmlXml
Xml
 
Extbase object to xml mapping
Extbase object to xml mappingExtbase object to xml mapping
Extbase object to xml mapping
 
XML
XMLXML
XML
 
DSpace 4.2 XMLUI Theming
DSpace 4.2 XMLUI ThemingDSpace 4.2 XMLUI Theming
DSpace 4.2 XMLUI Theming
 
Service Oriented Architecture -Unit II - Modeling databases in xml
Service Oriented Architecture -Unit II - Modeling databases in xml Service Oriented Architecture -Unit II - Modeling databases in xml
Service Oriented Architecture -Unit II - Modeling databases in xml
 
XML Document Object Model (DOM)
XML Document Object Model (DOM)XML Document Object Model (DOM)
XML Document Object Model (DOM)
 
Part 7
Part 7Part 7
Part 7
 

More from sana mateen

PHP Variables and scopes
PHP Variables and scopesPHP Variables and scopes
PHP Variables and scopessana mateen
 
Php and web forms
Php and web formsPhp and web forms
Php and web formssana mateen
 
Encryption in php
Encryption in phpEncryption in php
Encryption in phpsana mateen
 
Authentication methods
Authentication methodsAuthentication methods
Authentication methodssana mateen
 
Unit 1-subroutines in perl
Unit 1-subroutines in perlUnit 1-subroutines in perl
Unit 1-subroutines in perlsana mateen
 
Unit 1-uses for scripting languages,web scripting
Unit 1-uses for scripting languages,web scriptingUnit 1-uses for scripting languages,web scripting
Unit 1-uses for scripting languages,web scriptingsana mateen
 
Unit 1-strings,patterns and regular expressions
Unit 1-strings,patterns and regular expressionsUnit 1-strings,patterns and regular expressions
Unit 1-strings,patterns and regular expressionssana mateen
 
Unit 1-scalar expressions and control structures
Unit 1-scalar expressions and control structuresUnit 1-scalar expressions and control structures
Unit 1-scalar expressions and control structuressana mateen
 
Unit 1-perl names values and variables
Unit 1-perl names values and variablesUnit 1-perl names values and variables
Unit 1-perl names values and variablessana mateen
 
Unit 1-introduction to scripts
Unit 1-introduction to scriptsUnit 1-introduction to scripts
Unit 1-introduction to scriptssana mateen
 
Unit 1-introduction to perl
Unit 1-introduction to perlUnit 1-introduction to perl
Unit 1-introduction to perlsana mateen
 
Unit 1-array,lists and hashes
Unit 1-array,lists and hashesUnit 1-array,lists and hashes
Unit 1-array,lists and hashessana mateen
 
Uses for scripting languages,web scripting in perl
Uses for scripting languages,web scripting in perlUses for scripting languages,web scripting in perl
Uses for scripting languages,web scripting in perlsana mateen
 
Scalar expressions and control structures in perl
Scalar expressions and control structures in perlScalar expressions and control structures in perl
Scalar expressions and control structures in perlsana mateen
 

More from sana mateen (20)

Files
FilesFiles
Files
 
PHP Variables and scopes
PHP Variables and scopesPHP Variables and scopes
PHP Variables and scopes
 
Php intro
Php introPhp intro
Php intro
 
Php and web forms
Php and web formsPhp and web forms
Php and web forms
 
Mail
MailMail
Mail
 
Files in php
Files in phpFiles in php
Files in php
 
File upload php
File upload phpFile upload php
File upload php
 
Regex posix
Regex posixRegex posix
Regex posix
 
Encryption in php
Encryption in phpEncryption in php
Encryption in php
 
Authentication methods
Authentication methodsAuthentication methods
Authentication methods
 
Unit 1-subroutines in perl
Unit 1-subroutines in perlUnit 1-subroutines in perl
Unit 1-subroutines in perl
 
Unit 1-uses for scripting languages,web scripting
Unit 1-uses for scripting languages,web scriptingUnit 1-uses for scripting languages,web scripting
Unit 1-uses for scripting languages,web scripting
 
Unit 1-strings,patterns and regular expressions
Unit 1-strings,patterns and regular expressionsUnit 1-strings,patterns and regular expressions
Unit 1-strings,patterns and regular expressions
 
Unit 1-scalar expressions and control structures
Unit 1-scalar expressions and control structuresUnit 1-scalar expressions and control structures
Unit 1-scalar expressions and control structures
 
Unit 1-perl names values and variables
Unit 1-perl names values and variablesUnit 1-perl names values and variables
Unit 1-perl names values and variables
 
Unit 1-introduction to scripts
Unit 1-introduction to scriptsUnit 1-introduction to scripts
Unit 1-introduction to scripts
 
Unit 1-introduction to perl
Unit 1-introduction to perlUnit 1-introduction to perl
Unit 1-introduction to perl
 
Unit 1-array,lists and hashes
Unit 1-array,lists and hashesUnit 1-array,lists and hashes
Unit 1-array,lists and hashes
 
Uses for scripting languages,web scripting in perl
Uses for scripting languages,web scripting in perlUses for scripting languages,web scripting in perl
Uses for scripting languages,web scripting in perl
 
Scalar expressions and control structures in perl
Scalar expressions and control structures in perlScalar expressions and control structures in perl
Scalar expressions and control structures in perl
 

Recently uploaded

Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaOmar Fathy
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...SUHANI PANDEY
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.Kamal Acharya
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756dollysharma2066
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityMorshed Ahmed Rahath
 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projectssmsksolar
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptxJIT KUMAR GUPTA
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdfKamal Acharya
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringmulugeta48
 
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...soginsider
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...tanu pandey
 

Recently uploaded (20)

Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 

Dom parser

  • 2. DOM • The Document Object Model is an official recommendation of the World Wide Web Consortium (W3C). It defines an interface that enables programs to access and update the style, structure,and contents of XML documents. XML parsers that support the DOM implement that interface. • When to use? • You should use a DOM parser when: • You need to know a lot about the structure of a document • You need to move parts of the document around (you might want to sort certain elements, for example) • You need to use the information in the document more than once • What you get? • When you parse an XML document with a DOM parser, you get back a tree structure that contains all of the elements of your document. The DOM provides a variety of functions you can use to examine the contents and structure of the document.
  • 3.
  • 4. Common DOM methods • When you are working with the DOM, there are several methods you'll use often: • Document.getDocumentElement() - Returns the root element of the document. • Node.getFirstChild() - Returns the first child of a given Node. • Node.getLastChild() - Returns the last child of a given Node. • Node.getNextSibling() - These methods return the next sibling of a given Node. • Node.getPreviousSibling() - These methods return the previous sibling of a given Node. • Node.getAttribute(attrName) - For a given Node, returns the attribute with the requested name.
  • 5. Steps to Using DOM • Following are the steps used while parsing a document using DOM Parser. • Import XML-related packages. • Create a DocumentBuilder • Create a Document from a file or stream • Extract the root element • Examine attributes • Examine sub-elements • Import XML-related packages • import org.w3c.dom.*; • import javax.xml.parsers.*; • import java.io.*;
  • 6. • Create a DocumentBuilder • DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); • DocumentBuilder builder = factory.newDocumentBuilder(); • Create a Document from a file or stream • StringBuilder xmlStringBuilder = new StringBuilder(); xmlStringBuilder.append("<?xml version="1.0"?> <class> </class>"); ByteArrayInputStream input = new ByteArrayInputStream( xmlStringBuilder.toString().getBytes("UTF-8")); • Document doc = builder.parse(input); • Extract the root element • Element root = document.getDocumentElement(); • Examine attributes • //returns specific attribute • getAttribute("attributeName"); • //returns a (table) of names/values • getAttributes(); • Examine sub-elements • //returns a list of subelements of specified name getElementsByTagName("subelementName"); / • /returns a list of all child nodes • getChildNodes();
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12. SAX PARSER •SAX (the Simple API for XML) is an event-based parser for xml documents. • Unlike a DOM parser, a SAX parser creates no parse tree. SAX is a streaming interface for XML, which means that applications using SAX receive event notifications about the XML document being processed an element, and attribute, at a time in sequential order starting at the top of the document, and ending with the closing of the ROOT element.
  • 13. SAX • Reads an XML document from top to bottom, recognizing the tokens that make up a well-formed XML document • Tokens are processed in the same order that they appear in the document • Reports the application program the nature of tokens that the parser has encountered as they occur • The application program provides an "event" handler that must be registered with the parser • As the tokens are identified, callback methods in the handler are invoked with the relevant information
  • 14. When to use? • You should use a SAX parser when: • You can process the XML document in a linear fashion from the top down • The document is not deeply nested • You are processing a very large XML document whose DOM tree would consume too much memory.Typical DOM implementations use ten bytes of memory to represent one byte of XML • The problem to be solved involves only part of the XML document • Data is available as soon as it is seen by the parser, so SAX works well for an XML document that arrives over a stream • Disadvantages of SAX • We have no random access to an XML document since it is processed in a forward-only manner • If you need to keep track of data the parser has seen or change the order of items, you must write the code and store the data on your own