SAP SXML FORMATS ABEXA

Get Example source ABAP code based on a different SAP table
  


ARTICLE

sXML Library, Formats
This example demonstrates the four formats supported by sXML.

ABAP_SOURCE_CODE
ABAP_EXEC

ABAP_DESCRIPTION
A writer is created for each of the four formats and used in the method fill_writer to fill the string with XML data. A string writer can be created for all formats except XOP. A special XOP writer must be created for XOP. The XML complies with the JSON-XML rules and contain an element with raw data (the UTF-8 encoding of the string 'raw' with the hexadecimal value 726177). For each writer, the results are fetched using GET_OUTPUT and the binary content and the content of UTF-8 (default setting) represented in content converted to characters.
XML 1.0 The string contains the characters of the XML data in UTF-8 encoding. The raw data is represented in Base64 format, where 726177 is the same as the Base64 value 'cmF3'.
XOP The result of the writer is structured, where the component xop_document contains the string and the table-like component xop_parts contains the raw data. The content of the string is the same as in XML 1.0 format. The raw data is not represented in Base64, however, but is replaced by a reference to an external entity. The target of the reference is a table row in xop_parts, where the hexadecimal value 726177 is saved directly.
Binary XML The encoding of theXML data in the string uses the SAP-specific format with dedicated tokens. The hexadecimal value of the row data, 726177, can be found here directly. A direct conversion of UTF-8 to a character representation does not produce usable results. A file of this type can only be read by a specially designed parser.
JSON The string contains the characters of the JSON data written using JSON-XML in UTF-8 encoding. The raw data is represented in Base64 format.
Readers are created for the result of each writer in the method parse_outputs. The readers parse the results using two different methods, which are then compared:
The results are parsed in parallel loops using the method next_node . The equality of the attributes of the current nodes is then checked.
The identity transformation ID is called to create XML in a byte string from each result. The equality of this data is then checked.
The results demonstrate that the readers produce identical results for the four formats. Of special note is the fact that only the XOP reader has a special class, CL_SXML_XOP_READER, and the other readers all have the class CL_SXML_STRING_READER and can detect the format themselves.