0% found this document useful (0 votes)
48 views4 pages

XML Parsers

The document discusses different types of XML parsers including DOM and SAX parsers. DOM parsers create a tree structure of the XML document in memory, while SAX parsers are event-based and parse the XML document sequentially. Validation checks that an XML document is well-formed according to defined rules.

Uploaded by

Palani Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views4 pages

XML Parsers

The document discusses different types of XML parsers including DOM and SAX parsers. DOM parsers create a tree structure of the XML document in memory, while SAX parsers are event-based and parse the XML document sequentially. Validation checks that an XML document is well-formed according to defined rules.

Uploaded by

Palani Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

XML Parsers

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 parser validates the document and check that the document is well formatted.

Let's understand the working of XML parser by the figure given below:

Types of XML Parsers


These are the two main types of XML Parsers:

1. SAX

DOM (Document Object Model)


A DOM document is an object which contains all the information of an XML
document. It is composed like a tree structure. The DOM Parser implements a DOM
API. This API is very simple to use.

Features of DOM Parser


A DOM Parser creates an internal structure in memory which is a DOM document
object and the client applications get information of the original XML document by
invoking methods on this document object.
DOM Parser has a tree based structure.

Advantages
1) It supports both read and write operations and the API is very simple to use.

2) It is preferred when random access to widely separated parts of a document is


required.

Disadvantages
1) It is memory inefficient. (consumes more memory because the whole XML
document needs to loaded into memory).

2) It is comparatively slower than other parsers.

SAX (Simple API for XML)


A SAX Parser implements SAX API. This API is an event based API and less intuitive.

Features of SAX Parser


It does not create any internal structure.

Clients does not know what methods to call, they just overrides the methods of the
API and place his own code inside method.

It is an event based parser, it works like an event handler in Java.

Advantages
1) It is simple and memory efficient.

2) It is very fast and works for huge documents.

Disadvantages
1) It is event-based so its API is less intuitive.

2) Clients never know the full information because the data is broken into pieces.
XML Validation
A well formed XML document can be validated against DTD or Schema.

A well-formed XML document is an XML document with correct syntax. It is very


necessary to know about valid XML document before knowing XML validation.

Valid XML document


It must be well formed (satisfy all the basic syntax condition)

It should be behave according to predefined DTD or XML schema

69.7M
1.2K
Difference between JDK, JRE, and JVM

Rules for well formed XML


o It must begin with the XML declaration.
o It must have one unique root element.
o All start tags of XML documents must match end tags.
o XML tags are case sensitive.
o All elements must be closed.
o All elements must be properly nested.
o All attributes values must be quoted.
o XML entities must be used for special characters.
XML DTD
A DTD defines the legal elements of an XML document

In simple words we can say that a DTD defines the document structure with a list of
legal elements and attributes.

XML schema is a XML based alternative to DTD.

Actually DTD and XML schema both are used to form a well formed XML document.

We should avoid errors in XML documents because they will stop the XML programs.

XML schema
It is defined as an XML language

Uses namespaces to allow for reuses of existing definitions

It supports a large number of built in data types and definition of derived data types

You might also like