Skip to content

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

sXML Library, Transformation of Formats

This example demonstrates the transformation of various XML formats.

Other versions: 7.31 | 7.40 | 7.54

Source Code

REPORT demo_sxml_xml_to_binary_to_xop.

CLASS sxml_demo DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS main.
ENDCLASS.

CLASS sxml_demo IMPLEMENTATION.
  METHOD main.
    "XML 1.0
    DATA(xml_reader) = cl_sxml_string_reader=>create(
                         cl_abap_conv_codepage=>create_out( )->convert(
                          `<text><!-- comment -->blah</text>` ) ).

    "XML 1.0 to Binary XML
    DATA(binary_writer) = cl_sxml_string_writer=>create(
                            type = if_sxml=>co_xt_binary  ).
    xml_reader->next_node( ).
    xml_reader->skip_node( binary_writer ).
    DATA(binary_xml) =  binary_writer->get_output( ).

    "Binary XML to XOP
    DATA(binary_reader) = cl_sxml_string_reader=>create( binary_xml ).
    DATA(xop_writer) = cl_sxml_xop_writer=>create(  ).
    binary_reader->next_node( ).
    binary_reader->skip_node( xop_writer ).
    DATA(xop_package) = xop_writer->get_output( ).

    cl_demo_output=>display_xml( xop_package-xop_document ).
  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
  sxml_demo=>main( ).

Description

  • An XML string reader is filled with a byte string that contains XML data in XML 1.0 format and UTF-8 representation. This data is produced by the conversion of a text string from the current code page.

  • The method SKIP_NODE is used to pass the XML data of the reader to an XML writer for the Binary XML format. This data is then read to binary_xml.

  • The XML data in Binary XML format is passed to a further XML string reader and then transformed to an XOP writer.