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

sXML Library, Token-Based Parsing

In token-based parsing, the parser iterates across all nodes (tokens) in the tree structure of the XML data, one after the other. By default, the iterator passes across all subnode branches until the final node. The parser pauses after every iteration step on a node whose properties are available in the attributes of the XML reader. If the parser pauses on the node for an opened element, the list of the XML attributes there can be accessed.

Procedure (Principles)

An XML reader is created using the factory method CREATE of the class in question and by passing the source xml to the XML data, for example:

DATA(reader) = cl_sxml_string_reader=>create( xml ).

The static type of the reference variables is then the interface IF_SXML_READER and its methods and attributes can be addressed directly.

In the simplest parsing case, the method NEXT_NODE is applied as many times as it takes to reach the end of the XML:

reader->next_node( ).

Once the method is called, the attributes of the reader with the required properties of the node can be accessed directly. If the parser pauses on the node of an opened element, the method NEXT_ATTRIBUTE can be used to iterate across the list of attributes of an XML element:

reader->next_attribute( ).

After this method, the attributes of the reader object contain the name and the value of the current XML attribute. The end of the data is displayed by the value of the constants IF_SXML_NODE=>CO_NT_FINAL in the attribute NODE_TYPE. Any exceptions should be caught and handled in a TRY control structure.

Example

See Token-Based Parsing.

Methods and Attributes for Token-Based Parsing

Methods for token-based parsing

Alongside the simple iteration across nodes and attributes, the interfaces IF_SXML_READER offers several other methods for token-based parsing, summarized as follows:

Notes

Examples

Attributes for token-based parsing

The attributes of the reader with the properties of the current node are:

The value of the constants IF_SXML_NODE=>CO_NT_FINAL in the attribute NODE_TYPE indicate that the end of the XML data was reached.

Notes