Get Example source ABAP code based on a different SAP table
ABAP_SXML - Formats This example demonstrates the four formats supported by sXML.
ABAP_SOURCE_CODE DEMO CL_DEMO_SXML_FORMATS
ABAP_DESCRIPTION A writer is created for each of the four possible 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 data complies with the JSON-XML> rules and contains an element with raw data (the UTF-8 encoding of the string raw> with the hexadecimal value 726177). For each writer, the results are obtained 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 the hexadecimal value 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 format, 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 stored directly.
Binary XML The encoding of the XML data in the string uses the SAP-specific format with dedicated tokens. The hexadecimal value of the raw data, 726177, can be found here directly. A direct conversion of UTF-8 to a character representation does not produce readable results. A file of this type can only be read by a parser intended for this purpose.
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 show that the readers produce identical results for the four formats. It should be noted in particular 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.