Hitachi

uCosminexus Application Server XML Processor User Guide


C.1 Basic functionality of XML Processor

The basic functionality of XML Processor implements the XML document parsing that is required for the processing of the XML document. This subsection describes three types of parsing functionality (parser) provided by the basic functionality of XML Processor and the features of each parser.

Organization of this subsection

(1) DOM parser

(a) Overview

The DOM parser parses all the elements, attributes, and text included in an XML document, and expands their contents as an object tree called the DOM tree in the memory. By using the DOM API, you can freely traverse the DOM tree and you can reference, update, or delete any data item.

(b) Optimum usage

  • To process an XML document extensively

  • To process XML document content that requires processing in a complicated order

  • To edit the contents of an XML document

(2) SAX parser

(a) Overview

The SAX parser is an event-driven parser that parses an XML document sequentially from the beginning, and invokes predefined processing (callback method) whenever parsing events such as starting or stopping of elements, text, or processing instructions, occur.

When parsing starts, a callback method is invoked every time according to the type of the parsing event, and the parsing data, such as the element name or text data, is passed as an argument to the callback method.

You can perform processing in accordance with the content of the XML document by defining the processing content of the callback method in advance.

(b) Optimum usage

  • To process an XML document with a simple structure

  • For read-only processing, when the XML document contents need not be edited

(3) StAX parser

(a) Overview

The StAX parser, like the SAX parser, is an event-driven parser that parses an XML document sequentially from the beginning.

In the case of a StAX parser, parsing advances when the user requests a parsing event to the parser, and therefore, if you use a StAX parser, you can easily move ahead and interrupt the parsing process at any time. Also, by requesting a parsing event to a StAX parser, and assigning the processing as per the type and content of the parsing data acquired by requesting the parsing event, you can execute the processing in accordance with the contents of the XML document.

(b) Optimum usage

  • To process the contents of a huge XML document partially

(4) Merits and demerits of each parser

The following table describes the merits and demerits of each parser.

Table C‒2: Features of each parser

Parser type

Merit

Demerit

DOM parser

You can perform editing operations, such as addition or deletion, for an XML document.

Compared to the other parsers, the amount of memory consumed is large and the processing speed is slow.

SAX parser

Compared to the other parsers, the amount of memory consumed is small, and the processing speed is high.

You cannot perform editing operations, such as addition or deletion, for an XML document.

StAX parser

In addition to the above merits of the SAX parser, the user can control the execution or interruption of parsing.

The XML schema-based validation cannot be executed with the StAX parser alone.