II UNIT PPT NOTES.pdf this is the data structures

PriyankaRamavath3 16 views 60 slides May 29, 2024
Slide 1
Slide 1 of 60
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51
Slide 52
52
Slide 53
53
Slide 54
54
Slide 55
55
Slide 56
56
Slide 57
57
Slide 58
58
Slide 59
59
Slide 60
60

About This Presentation

Xtm tags


Slide Content

XML
(eXtensible Markup Language)

Introduction:
•XMLstandsforeXtensibleMarkupLanguageanditisused
forstoringandtransferringdata.
•XMLdoesn’tdependontheplatformandthesoftware
(programminglanguage).i.e.wecanabletowriteaprogram
inanylanguageonanyplatform(OperatingSystem)tosend,
receiveorstoredatausingXML.
•XMLisasimpledocumentwiththedata,whichcanbeusedto
storeandtransferdatabetweenanysystemsirrespectiveof
theirhardwareandsoftwarecompatibilities.
•ItissomucheasiertoreadthedatafromXMLanddisplayit
onaGUI(graphicaluserinterface)usingmarkuplanguage
likeHTML.

HTML VsXML
HTML(Hyper Text Markup Language)XML(eXtensible Markup Language)
HTMLisnotacasesensitivelanguageXMLiscasesensitivelanguage
HTMLismainlyconcernedwiththe
presentationofdata
XMLismainlyusedforstoringand
transportingthedata
HTMLisstatic XMLisdynamic
InHTMLtheclosingtaginoptional InXMLtheclosingtagismandatory
HTMLusespredefinedtagssuchas<b>,
<br>,<img>etc.
XMLusestheuser-definedtagsthatwe
createwhilewritingtheXMLdocument.
HTMLdoesnotpreservewhitespace.XMLpreserveswhitespace.
HTMLAttributeValuesQuotingis
optional.
XMLAttributeValuesMustAlwaysbe
Quoted.

Simple XML document example
A XML document structure looks like this:
<root>
<child>
<subchild>.....</subchild>
</child>
<child>
<subchild>.....</subchild>
</child>
</root>
•<?xmlversion="1.0"encoding="UTF-8"?>iscalledXMLProlog.
•Itisoptional,howeverwhenweincludeitintheXMLdocument,it
shouldalwaysbethefirstlineofthedocument.XMLPrologdefinesthe
XMLversionandtheencodingusedintheXMLdocument.

•The XML code can be written on a simple notepad and should be saved as
“filename.xml”.
Students.xml
<?xml version="1.0" encoding="UTF-8"?>
<students>
<student>
<num>527</num>
<name>Ravi</name>
<age>20</age>
</student>
<student>
<num>572</num>
<name>Dev</name>
<age>23</age>
</student>
</students>

•IntheaboveXMLdocumentwehavethedetailsofthefewstudents.
Here<students>istherootelement,<student>isthechildelementand
num,nameandagearesub-childelements.
Output:

XML Syntax
Root Element is mandatory in XML
•XML document must have a root element. A root element can
have child elements and sub-child elements.
•For example: In the following XML document, <message> is the
root element and <to>, <from>, <subject> and <text> are child
elements.
<?xml version="1.0" encoding="UTF-8"?>
<message>
<to>Durga</to>
<from>Madhu</from>
<subject>Message from teacher to Student</subject>
<text>You have an exam tomorrow at 10:00 AM</text>
</message>

XML Syntax Contd…
XMLiscasesensitive
XMLisacasesensitivelanguage.
Forexample:
<from>madhu</from>Thisisvalid
<from>Prasad</FROM>Thisisinvalid
•Alllettersofclosingtagisincapitalwhilealllettersofopening
tagisinsmall,thisisanexampleofinvalidXML.
XMLProlog
<?xmlversion="1.0"encoding="UTF-8"?>
•ThislineiscalledtheXMLProlog.Itisanoptionalline,however
itshouldbethefirstlinewhenyoumentionit.Itspecifiesthe
XMLversionandtheencodingusedintheXMLdocument.

XML Syntax Contd…
Elementsshouldnotoverlap
•AlltheelementsinXMLshouldbeproperlynestedandtheyshouldnot
overlap.
<class><teacher>Madhu</class></teacher> -->Wrong (Not nested properly)
<class><teacher>Durga</teacher></class>-->Correct(Correctlynested)
XMLelementsmusthaveaclosingtag
•AllXMLdocumentsmusthaveaclosingtag.
<textcategory=message>hello</text>-->correct
<textcategory=message>hello-->wrong
CommentsinXML
•ThisishowacommentshouldlooklikeinXMLdocument.
<!--Thisisjustacomment-->

XML Attributes
•XMLelementscanhaveattributes.Bytheuseofattributeswecan
addtheadditionalinformationabouttheelement.
•XMLattributesareawaytoaddadditionaldatatotheXML
element.Attributescontaindatainformofname&valuepairs.
•XMLattributesareusedtoenhancethepropertiesoftheelements.
Note:XMLattributesmustalwaysbequoted.Wecanusesingleor
doublequote.
Example:
<bookcategory="computers">
<price>1000rs</price>
<publisher>TataMcGrawHill</publisher>
</book>

XML Attributes Contd…
XMLattributesvsXMLSubElements:
•TheDatacanbestoredinattributesorinchildelements.Butthereare
somelimitationsinusingattributes,overchildelements.
Sameinformationcanberepresentedintwoways:
1
st
Way:
<bookcategory="computers">
<price>1000rs</price>
<publisher>TataMcGrawHill</publisher>
</book>
2
nd
Way:
<book>
<category>computers</category>
<price>1000rs</price>
<publisher>TataMcGrawHill</publisher>
</book>

XML Attributes Contd…
•Inthefirstwaycategoryisusedasanattributeandinthesecond
waycategoryisusedasanelement.
•Bothexamplesprovidethesameinformationbutitisgoodpractice
toavoidattributeinXMLanduseelementsinsteadofattributes.
Because
•Attributescannotcontainmultiplevaluesbutchildelementscan
havemultiplevalues.
•Attributes cannot contain tree structure but child element can.
•Elements are easy to be handled by the programming language
compared to the attributes.

XML Validation
Document Type Definition
(DTD)

XML –Validation
•ValidationisaprocessbywhichanXMLdocumentisvalidated.
•AnXMLdocumentwithcorrectsyntaxisknownasvalidXML
document.
Let‟sseefewimportantrulestocheckforsyntaxerrors.
•AllXMLdocumentsmusthavearootelement.
•XML is a case sensitive language so you should be careful with the
case while opening and closing tags.
•All XML tags must have a closing tag.
•XML attribute name should not be quoted while its value must be
quoted.
•TherearetwowaystocheckwhethertheXMLdocumentisvalid.
1XMLDTD(DocumentTypeDefinition)
2XML Schema

Document Type Definition (DTD)
•DTDstandsforDocumentTypeDefinition.Itisusedtodefine
documentstructurewithalistoflegalelementsandattributes.
•DocumentTypeDefinition(DTD)isacertainpieceofcode,
whichcandefinesstructureofXMLdocument.
•EachDTDcontainsalistofelements,whichspecifiestherules
forstructuringagivenXMLdocument.
•EachDTDspecifiestherelationshipbetweenrootelement,child
elementsandsubchildelements.
•AnXMLdocumentisconsidered“wellformed”and“valid”ifit
issuccessfullyvalidatedagainstDTD.

Document Type Definition (DTD) Contd..
•DTD‟sareoptionalinXML,butrecommendedforclarity
purpose.
•DTD‟scanbedeclaredinternally(WithinXMLdoc)andasan
externalfile(withinaseparatefilewith“.dtd”extension).
BasicBuildingBlocks:
Thereare4buildingblockstobuildaXMLdocumentwithDTD.
thoseare
1.Tags
2.Elements
3.Attributes
4.Entities

Document Type Definition (DTD) Contd..
1.Tags:
–TheXMLallowstheusertocreateowntags.Useallythetag
<tagname>isanOpeningtag,</tagname>referstoitsequivalent
closingtag.
Example:
<book>LetusC</book>
<author>YashwantKanetkar</author>
–InXMLthetagsarecasesensitive.Andclosingtagismandatory.
–AlltheelementsinXMLshouldbeproperlynestedandthey
shouldnotoverlap.

Document Type Definition (DTD) Contd..
2.ElementsinDTD:
–TheDTDdocumentiscomposedwithvariouselements.These
elementsareusedtorepresentthetagsinXMLdocument.
Declaration:
<!ELEMENTname-of-element(context)>
–Todeclareanemptyelement
Syntax:
<!ELEMENTname-of-element(EMPTY)>
–Todeclareanelement,thiscarriesdata
Syntax:
<!ELEMENTname-of-element(#PCDATA)>
(or)
<!ELEMENTname-of-element(#CDATA)>

Document Type Definition (DTD) Contd..
–Todeclareanelement,thiscontainschildelements
Syntax:
<!ELEMENTname-of-element(child-names)>
Examples:
<!ELEMENTstudent(id,name,age)>
<!ELEMENTname(#PCDATA)>
<!ELEMENTage(EMPTY)>
3.Attributes:
•These are used to provide the additional information along with
elements.
•In DTD, the attributes are declared by using “ATTLIST” Keyword.
Syntax:
<! ATTLIST name-of-element name-of-attribute
attribute-type [default-value]>

Document Type Definition (DTD) Contd..
•In the above syntax, the field „attribute-type‟ can specifies the
following pre-defined values.
•ID:It is a value which remains unique.
•CDATA:The value supplied here is nothing but character data.
•ENTITY:The value supplied in this case is nothing but an entity.
•In the same way, the filed „default-value‟ can specifies the following
pre-defined values.
#REQUIRED: It means the value for the attribute is required.
#IMPLIED: It means the attribute is not required.
#FIXED: Here a fixed value is supplied.
Default-value: It is a default value of given attribute.
Example:
<! ATTLIST student address CDATA #REQUIRED>

Document Type Definition (DTD) Contd..
4.Entities:
•Some markup elements can contain complex data; these types of
elements are called as Entities.
•These are used to create small piece of data which you want you use
repeatedly throughout your schema.
Syntax:
<! ENTITY name-of-entity “value”>
Example:
<! ENTITY Book “Web Technologies”>
Used as
<author> the &Book author is UttamK Roy</author>

Document Type Definition (DTD) Contd..
•DTD‟s can be declared internally (With in XML doc) and as an
external file (with in a separate file with “.dtd” extension)
Example with external DTD:
•Create a DTD for a remainder; it has following remainderas root
element and child elements-heading, to, from, message.
“remainder.dtd”
<!ELEMENT remainder(heading,to,from,message)>
<!ELEMENT heading(#PCDATA)>
<!ELEMENT to(#PCDATA)>
<!ELEMENT from(#PCDATA)>
<!ELEMENT message(#PCDATA)>

Document Type Definition (DTD) Contd..
“remainder.xml”
<?xml version="1.0"?>
<!DOCTYPE note SYSTEM "remainder.dtd">
<remainder>
<heading>Final Remainder</heading>
<to>Mr.Madhu</to>
<from> Ravi Gupta</from>
<message> Date of joining is 5th Feb</message>
</remainder>
Output:

Document Type Definition (DTD) Contd..
Example with internal DTD:
“remainderdemo.xml”
<?xml version="1.0"?>
<!DOCTYPE note [
<!ELEMENT remainder (heading,to,from,message)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT message (#PCDATA)>
]>
<remainder>
<heading>Final Remainder</heading>
<to>Mr.Madhu</to>
<from> Ravi Gupta</from>
<message> Date of joining is 5th Feb</message>
</remainder>

Document Type Definition (DTD) Contd..
Example:
•CreateaDTDforacatalogoffourstrokeenginemotorbikeswhere
eachmotorbikehasthefollowingchildelements:make,model,
year,color,engine,chassisnumberandaccessories.Theengine
elementhaschildelementsthoseare–enginenumber,numberof
cylinders,typeoffuel.Theaccessorieselementshastheattributes
likediskbreak,autostartandradio,eachofwhichrequiredandhas
thepossiblevalues‘YES’and‘NO’.Entitiesmustbedeclaredforthe
namesofthepopularmotorbikemakes.

Document Type Definition (DTD) Contd..
“bikecatalog.dtd”
<!ELEMENT catalog (motorbike)*>
<!ELEMENT motorbike (make, model,year,color,engine, chasis_num, accessories)>
<!ELEMENT make (#PCDATA)>
<!ELEMENT model (#PCDATA)>
<!ELEMENT year (#PCDATA)>
<!ELEMENT color (#PCDATA)>
<!ELEMENT engine (engine_num,cylinder_num,fuel_type)>
<!ELEMENT engine_num(#PCDATA)>
<!ELEMENT cylinder_num(#PCDATA)>
<!ELEMENT fuel_type(#PCDATA)>
<!ELEMENT chasis_num(#PCDATA)>
<!ELEMENT accessories (#PCDATA)>
<!ATTLIST accessories diskbrake(Yes|No) #REQUIRED autostart(Yes|No)
#REQUIRED radio (Yes|No) #REQUIRED>

Document Type Definition (DTD) Contd..
<?xml version="1.0"?> “bikecatalog.xml”
<!DOCTYPE catalog SYSTEM "bikecatalog.dtd">
<catalog>
<motorbike>
<make>Hero</make>
<model>Glammur120cc</model>
<year>2014</year>
<color>Red-Black</color>
<engine>
<engine_num>564789</engine_num>
<cylider_num>32</cylider_num>
<fuel_type>PreMimum</fuel_type>
</engine>
<chasis_num>546</chasis_num>
<accessories discbrake="Yes" autostart="Yes" radio="No"/>
</motorbike>
</catalog>

XML Validation
XML Schema

XML Schema (Or) XML Schema Definition (XSD)
•XMLSchemamainlyusedforstructuringXMLdocuments.
SimilartoDTD,XMLSchemaisalsousedtocheckwhether
thegivenXMLdocumentis“wellformed”and“valid”.
•XMLSchemacanbedefinedrootelement,childelements,
theirnumberaswellastheirorder.
•Itdefinesdatatypes,defaultandfixedvaluesforthe
elementsandattributes.
•Forthispurpose,ithastheformofXMLschemalanguage
whichisalsoknownasXmlSchemaDefinition(XSD).

XML Schema Contd...
•XMLschemasarecreatedbyusingXMLsyntax,where
DTDuseaseparatesyntax.
•XMLSchemasspecifythetypeoftextualdatathatcanbe
usedwithinattributesandelements.
•IfweusetheXMLSchemaforcomplexandlarge
operations,thentheprocessingofXMLdocumentmayslow
down.
•TheXMLdocumentcan’tbedisplayedifthecorresponding
schemafileisabsent.

XML Schema Contd...
Data Types in XML Schema:
•Binary data type: It includes the binary data (0’s or 1’s).
•Boolean data type: It includes either “true” or “false”.
•Number data type: There are 3 main number data types those are
ofloat : It contains 32-bit floating point values.
odouble: It contains 64-bit floating point values.
odecimal: It includes the decimal numbers either +veor –ve.
•Date data type: It specifies the current date (YYYY-MM-DD).
•Time data type: It specifies the current time (HH:MM:SS).
•String data type: It includes series of characters such as strings.

•Example: The following example is an XML schema file called
“remainder.xsd” that defines the elements of XML document.
“remainder.xsd”
<?xml version = "1.0" encoding = "UTF-8"?>
<xs:schemaxmlns:xs= "http://www.w3.org/2001/XMLSchema">
<xs:elementname="remainder">
<xs:complextype>
<xs:sequence>
<xs:elementname="to" type="xs:string">
<xs:elementname="from" type="xs:string">
<xs:elementname="heading" type="xs:string">
<xs:elementname="msg" type="xs:string">
</xs:sequence>
</xs:complextype>
</xs:schema>

“remaind.xml”
<?xml version = "1.0" encoding = "UTF-8"?>
<remainder schemaLocation="remainder.xsd">
<to>Madhu</to>
<from>Durga</from>
<heading>Notice</heading>
<msg>This is My Last Remainder</msg>
</remainder>
Output:

XHTML-
(eXtensibleHyperTextMarkupLanguage)

•XHTMLstandsforEXtensibleHyperTextMarkup
Language.
•XHTMLisalmostidenticaltoHTMLbutitisstricter
thanHTML.XHTMLisHTMLdefinedasanXML
application.Itissupportedbyallmajorbrowsers.
•AlthoughXHTMLisalmostthesameasHTMLbutItis
moreimportanttocreateyourcodecorrectly,
becauseXHTMLisstricterthanHTMLinsyntaxand
casesensitivity.
•XHTMLwasdevelopedtomakeHTMLmore
extensibleandstandard.

Let's take an example,
ThefollowingHTMLcodeworksfineinmostbrowsers(evenif
itdoesnotfollowtheHTMLrules).
“Bad.html”
<html>
<head>
<title>ThisisanexampleofbadHTML</title>
<body>
<h1>This is a heading
<p>Thisisaparagraph
</body>
TheaboveHTMLcodedoesn'tfollowtheHTMLrulealthough
itruns.
XHTMLdoesn'tfacilitateyoutomakebadlyformedcode(like
missingoutaclosingtag).

There are some changes in XHTML as compared to HTML, those
are
Changes in Document Structure
•All documents must have a DOCTYPE.
•The xmlns attribute in <html> is mandatory and must specify
the xml namespace for the document.
•<html>, <head>, <title>, and <body> are mandatory with their
respective closing tags.
Changes in XHTML Tags
•All XHTML tags must be in lower case.
•All XHTML tags must be closed.
•All XHTML tags must be properly nested.
•All XHTML attributes must be in lower case.
•The name attribute has changed as id.
•XHTML attribute values must be quoted.

•All XHTML documents must contain a DOCTYPE declaration at the
start.
–Example:<!DOCTYPEhtml>
•XHTMLiscase-sensitivemarkuplanguage.So,alltheXHTMLtags
andattributesmustbewritteninlowercase.
–Example:
<!--InvalidinXHTML-->
<AHref=“file.html“>Click here</A>
<!--ValidinXHTML-->
<ahref=“file.html“>Click here </a>
•AnXHTMLmusthaveanequivalentclosingtag.
–Example:
<!--InvalidinXHTML-->
<p>Thisparagraph not valid inXHTML.
<!--ValidinXHTML-->
<p> Thisparagraph valid inXHTML. </p>

•All the XHTML attribute's values must be quoted.
–Example:
<!--InvalidinXHTML-->
<imgsrc=“xhtml.gif"width=250height=50/>
<!--ValidinXHTML-->
<imgsrc=“xhtml.gif"width="250"height="50"/>
•The id attribute is used to replace the name attribute. Instead of
using name = "name", XHTML prefers to use id = "id".
–Example:
<!--InvalidinXHTML-->
<inputtype=“text“name=“txtuname”/>
<!--ValidinXHTML-->
< inputtype=“text“id=“txtuname” />

Example:
<!DOCTYPEhtml>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Titleofdocument</title>
</head> Output:
<body bgcolor=“cyan”>
somecontent
</body>
</html>

XML Parsers
(DOM &SAX)

XML Parsers
•AnXMLparserisasoftwarelibraryorpackagethat
providesinterfacesforclientapplicationstoworkwithan
XMLdocument.
•TheXMLParserisdesignedtoreadtheXMLdocumentand
createaway(interfaceorAPI)forprogramstouseXML.

XML Parsers
Two Types of parsers
DOM Parser
SAX Parser

DOM (Document Object Model)
•DOMisaplatformthatallowsprogramsandscriptsto
dynamicallyaccessandupdatethecontentandstructureofa
XMLdocuments.
•TheDocumentObjectModel(DOM)isaprogrammingAPI
forHTMLandXMLdocuments.Itdefinesthelogical
structureofdocumentsandprovidesinterface(API)for
accessdocuments.
•TheDocumentObjectModelcanbeusedwithany
programminglanguage.
•DOMexposesthewholedocumenttoapplications.

DOM (Document Object Model)
•TheXMLDOMdefinesastandardwayforaccessingand
manipulatingXMLdocuments.ItpresentsanXMLdocument
asatree-structure.
•ThetreestructuremakeseasytodescribeanXMLdocument.A
treestructurecontainsrootelement(asparent),childelement
andsoon.
•TheXMLDOMmakesatree-structureviewforanXML
document.
•WecanaccessallelementsthroughtheDOMtree.Wecan
modifyordeletetheircontentandalsocreatenewelements.

DOM (Document Object Model)
<?xml version="1.0"?>
<college>
<student>
<firstname>Durga</firstname>
<lastname>Madhu</lastname>
<contact>999123456</contact>
<email>[email protected]</email>
<address>
<city>Hyderabad</city>
<state>TS</state>
<pin>500088</pin>
</address>
</student>
</college>

DOM (Document Object Model)
Let's see the tree-structure representation of the above example.

DOM (Document Object Model)
•WeneedaparsertoreadXMLdocumentintomemoryand
convertsintoXMLDOMObjectthatcanbeaccesseswith
anyprogramminglanguage(herewecanusePHP).
•TheDOMparserfunctionsarepartofthePHPcore.Thereis
noinstallationneededtousethesefunctions.
•ToloadXMLdocumentinPHP
$xmlDoc=newDOMDocument();
thisstatementcreatesanobject.
$xmlDoc->load("note.xml");
thisstatementloadsaxmlfilebyusingobject.

DOM (Document Object Model)
These are some typical DOM properties in php:
•X -> nodeName-the name of X
•X -> nodeValue-the value of X
•X->parentNode-the parent node of X
•X->childNodes-the child nodes of X
•X->attributes -the attributes nodes of X
Where X is Node object.
“note.xml”
<?xml version="1.0" encoding="UTF-8"?>
<student>
<num>521</num>
<name>xyz</name>
<age>30</age>
</student>

DOM (Document Object Model)
“Note.php”
<?php
$xmlDoc= new DOMDocument();
$xmlDoc->load("note.xml");
$x = $xmlDoc->documentElement;
foreach($x->childNodesAS $item) {
print $item->nodeValue. "<br>";
}
?>
Output:

SAX
Simple API for XML

XML Parsers
What is an XML parser?
–An XML parser is a software library or package
that provides interfaces for client applications to
work with an XML document.
–The XML Parser is designed to read the XML and
create a way for programs to use XML.

XML Parsers
Two types of parser
–SAX (Simple API for XML)
•Event driven API
•Sends events to the application as the document is read
–DOM (Document Object Model)
•Reads the entire document into memory in a tree
structure

Simple API for XML

SAX Parser
When should I use it?
–Large documents
–Memory constrained devices
–If you need not to modify the document

SAX Parser
Which languages are supported?
–Java
–Perl
–C++
–Python

SAX Implementation in Java
•Create a class which extends the SAX event handler
Import org.xml.sax.*;
import org.xml.sax.helpers.ParserFactory;
Public class SaxApplication extends HandlerBase {
public static void main(String args[]) {
}
}

SAX Implementation in Java
•Create a SAX Parser
public static void main(args[]) {
String parserName= “org.apache.xerces.parsers.SAXParser”;
try {
SaxApplicationapp = new SaxApplication();
Parser parser= ParserFactory.makeParser(parserName);
parser.setDocumentHandler(app);
parser.setErrorHandler(app);
parser.parse(new InputSource(args[0]));
} catch (Throwablet) {
// Handle exceptions
}
}

SAX Implementation in Java
•Most important methods to parse
–void startDocument()
•Called once when document parsing begins
–void endDocument()
•Called once when parsing ends
–void startElement(...)
•Called each time an element begin tag is encountered
–void endElement(...)
•Called each time an element end tag is encountered
–void error(...)
•Called once when parsing error occurred.

DOM SAX
Tree model parser (Object based) (Tree
of nodes).
Event based parser (Sequence of
events).
DOM loads the file into the memory and
then parse-the file.
SAX parses the file as it reads it, i.e.
parses node by node.
Has memory constraints since it loads
the whole XML file before parsing.
No memory constraints as it does not
store the XML content in the memory.
DOM is read and write (can insert or
delete nodes).
SAX is read only i.e. can’t insert or
delete the node.
If the XML content is small, then prefer
DOM parser.
Use SAX parser when XMLcontent is
large.
Backward and forward search is possible
for searching the tags and evaluation of
the information inside the tags.
SAX reads the XML file from top to
bottom and backward navigation is not
possible.
Slower at run time. Faster at run time.