sXML Library - Parse
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:
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:
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 only the XOP format. 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 reader position
of a reader is controlled while parsing using its methods. The actions permitted by a reader are specified
by its current reader 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.
7.31 | 7.40 | 7.54
- 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.