Home >>XML Tutorial >XML Parsers

XML Parsers

XML Parsers

An XML parser is a software library or package that provides interfaces for an XML text to interact for client applications. The XML Parser is designed to interpret the XML and create a way to use XML in programs.

XML parser validates the text and verifies that it is well-formatted.

Let's understand XML parser feature by the following figure:

XML Parsers

Types of XML Parsers

These are the two main types of XML Parsers:

  1. DOM
  2. SAX

DOM (Document Object Model)

A DOM document is an entity that comprises all of the XML document information. It is constructed like the structure of a tree. A DOM API is introduced by the DOM Parser. This API is incredibly easy to use.

Features of DOM Parser

A DOM Parser generates an internal memory representation and is an entity of a DOM document and the client applications obtain information regarding the initial XML document by executing methods on this entity.

DOM Parser has structure centered on a tree.

Advantages

  1. All read and write operations are provided, and the API is quite easy to use.
  2. This is preferred if access to widely separated parts of a document is needed at random.

Disadvantages

  1. This is inefficient memory. (consume more memory, since the whole XML document needs to be loaded into memory).
  2. This 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

This has no internal structure.

Clients don't know which methods to call, they simply override the API methods and put their own application within the method.

It is an event-based parser, it functions like a Java event handler.

Advantages

  1. It is easy and memory efficient.
  2. It is really easy and works with huge documents.

Disadvantages

  1. This is event-based and thus the API is less intuitive.
  2. Clients are never fully informed of the information as the data is broken down into pieces.

Several commercial products are accessible to ease the parsing process, which facilitate the breakdown of XML document and yield more reliable outcomes.

The following lists some commonly used parsers −

  • MSXML (Microsoft Standard XML Services) − It is a basic suite of Microsoft XML tools with a parser in it.
  • System. Xml. XmlDocument − This class is part of the. NET library, which includes a number of different classes relating to XML work.
  • Java built-in parser − It has its own parser in the Java library. The library is structured in such a way that an external application such as Apache or Saxon Xerces will replace the built-in parser.
  • Saxon − Saxon provides tools to parse, transform, and query XML.
  • Xerces − Xerces is built in Java and produced by the renowned open source project Apache Software.

No Sidebar ads