Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Data Interfaces and Communication Interfaces →  ABAP and XML →  Class Libraries for XML →  sXML Library 

sXML Library - Parsing

XML data can be read using sXML Library or simply have its syntax checked by being associated with an XML reader and its methods. A reader like this is "validating", meaning that invalid XML data raises an exception. It interprets the XML data as a hierarchical tree-like structure where each token is represented by a node assigned uniquely to a subnode (see W3C Information Set). An element with a literal value, for example, is interpreted as follows:

|
|--CO_NT_ELEMENT_OPEN
|    |
|    |--CO_NT_VALUE
|
|--CO_NT_ELEMENT_CLOSE

The value is a subnode of the node that represents an opened element. The names of the nodes here are the same as the constants of the interface IF_SXML_READER that describe the type of a node. The attributes of an element have a special task. They are assigned as a list to the node with the type CO_NT_ELEMENT_OPEN and can be reached using special methods when the parser is paused on the opened element.

The classes and interfaces in sXML Library available for parsing XML data are organized so that there are separate XML reader classes for different requirements. These classes inherit from the abstract superclass CL_SXML_READER. The abstract superclass contains implementations of functions required by all readers and includes the interface IF_SXML_READER, which contains the components shared by all readers. This interface enables all readers to be accessed in the same way. If special components need to be accessed that are not declared in the interface, a down cast must be used on the class in question.

The specialized reader classes are:

  • CL_SXML_STRING_READER
Readers in this class parse XML data in a byte string.
  • CL_SXML_TABLE_READER
Readers in this class parse XML data in an internal table with a flat byte-like row type.
  • CL_SXML_DATASET_READER
Readers in this class parse XML data in a file on the host computer of the current AS Instance.
  • CL_SXML_HTTP_READER
Readers of this class parse XML data from an HTTP service in ICF.
  • CL_SXML_XOP_READER
Readers in this class parse XML data saved in XOP format.

The XML data pending parsing is passed to the factory method CREATE of each reader. Readers detect the format and the character format of the data themselves. Except for the XOP reader, readers support all formats except XOP. The XOP reader supports the XOP format only. Instructions on standardization and handling empty space can be passed to the factory method if permitted by the format.

The methods of the interface IF_SXML_READER enable serial parsing of the passed XML data. There are two basic ways to do this:

A reader cannot be used more than once for the same XML data or for other data. The reading position of a reader is controlled while parsing using its methods. The actions permitted by a reader are specified by its current reading position. For example, a reader located at the end of the parsed XML data can no longer be used as an XML source of the statement CALL TRANSFORMATION. No method exists that can restore the reader to its initial state. A new reader is created instead.

Other versions: 7.31 | 7.40 | 7.54


Notes

  • The parser in sXML Library is a more strict validator than the parser in iXML Library. A namespace prefix must be declared in the same element or in a superelement. Preceding declarations in a parallel element are interpreted as errors.

  • An XML reader in sXML Library can be specified as an XML source of the statement CALL TRANSFORMATION. This enables transformations to be performed for all sources supported by sXML readers in all supported formats. In particular, this makes it possible for JSON data to also be consumed directly by ABAP data objects.

  • The method SKIP_NODE, which can be used in both token-based and object-oriented parsing, offers various simple ways of checking the validity of a subtree or tree or of copying a tree to a writer (which changes its format).

  • If the content of elements or attributes contain the notations <, >, &, ", or ', they are transformed automatically to the corresponding characters when parsed.

Executable Example

Transformation from XML Reader

Continue

sXML Library - Token-Based Parsing

sXML Library - Object-Oriented Parsing