SAP ABAP IXML LIB

Get Example source ABAP code based on a different SAP table
  


ARTICLE

iXML Library
ITOC

API of iXML Library
iXML Library provides an API for handling XML documents in DOM format. This API enables
XML data to be parsed to DOM format,
reads and writes to be performed on XML documents in DOM format (including creating new documents),
XML documents in DOM format to be rendered to XML data.
In ABAP programs, the API is implemented using interfaces from the class library with the naming convention IF_IXML_.... The access class CL_IXML contains factory methods for creating objects such as streams, parsers, documents, and renderers. These objects are then accessed using interface reference variables. The classes and interfaces are documented in Class Builder.

Notes
The classes and interfaces in iXML Library in package SIXML wrap classes and interfaces implemented in C++, delivered as part of the ABAP Kernel.
Separate versions for C++ and C are also delivered, with the C version being a wrapper of the library implemented in C++.
iXML Library supports the Unicode character format UCS-2. Characters from the surrogate area are not supported and can be rejected as invalid.
DOM in iXML Library and its associated methods are also used internally in calls of XSL transformations with the statement CALL TRANSFORMATION.

Access to iXML Library
Precisely one factory object of the access class CL_IXML is required for accessing iXML Library in an ABAP program. This object is created as follows: DATA(ixml) = cl_ixml=>create( ).
The static type of the reference variable ixml is then the interface IF_IXML, which contains all factory methods required to create further objects, such as streams, XML documents, parsers, or renderers. This factory object is a singleton and can only be instantiated once in one internal session.

Services in iXML Library
The most important services offered by the classes and interfaces in iXML Library are as follows:
XML parser The XML parser analyzes the syntax of an XML file provided in an input stream to check whether it is correct and creates an XML document in a DOM representation from this file. The document can then be accessed using interfaces. The DOM can be created as follows:
Complete Parsing to DOM
The parser creates the XML document in a DOM representation for the complete XML data in a single action and passes it to the memory.
Sequential Parsing
The parser processes the input stream in sequential actions, where each sequence is determined by events that can be accessed using the interface IF_IXML_EVENT. The application can edit each sequence while the parser is running. It is possible to configure whether a full XML documented is saved to DOM representation.
Parsing to Data Objects
When parsing to data objects, the tokens of the parsed XML data is written directly to ABAP data objects (structures, internal tables). An XML document in DOM representation can also be saved.
Access to DOM An XML document represented as DOM is in a standardized tree representation. For each logical unit of the XML document, there is a node object of an associated class that implements specialized interfaces. An ABAP program can use the interfa ces to perform reads and writes to the XML document. The classes of the node objects are not usually used directly in the program.
XML renderer The XML renderer creates XML data from an XML document saved as DOM. This document is created by parsing (both with and without follow-up modifications) or created as a complete new document using the methods of the DOM interface. The renderer then passes the data to an output stream.

Notes
One benefit of DOM is simple access to the individual parts of an XML document. It also has the drawback, however, of using more memory, up to ten times the actual size of the document. Note that the d ocument itself can already use more memory for its markup than for the actual data. This memory use can be restricted by preventing a complete DOM from being created by sequential parsing or by parsing to data objects.
The DOM in iXML Library also includes DTDs ( Document Type Definitions).
If XML data needs to be parsed and rendered only and no XML documents in DOM representation and no DTDs are needed, sXML Library provides an alternative with better performance than iXML Library.
iXML only supports the XML 1.0 format, where, XML data is represented in a particular character format using a character string. sXML Library supports more formats.
For examples, see the corresponding programs in the example library and the package SIXML_TEST.