SAP NetWeaver AS ABAP Release 740, ©Copyright 2014 SAP AG. All rights reserved.
ABAP Keyword Documentation → ABAP − Reference → Data Interfaces and Communication Interfaces → ABAP and XML → Class Libraries for XML → sXML Library →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.
Notes
Example
Transformation from a XML Reader.