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 to an XML Writer

Transformation of ABAP data to an XML writer.

Other versions: 7.31 | 7.40 | 7.54

Source Code

REPORT demo_sxml_trafo_into_writer.

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

CLASS sxml_demo IMPLEMENTATION.
  METHOD main.
    DATA(writer) =
      CAST if_sxml_writer( cl_sxml_string_writer=>create(  ) ).
    writer->open_element( name = 'document' ).
    writer->open_element( name = 'head' ).
    writer->open_element( name = 'author' ).
    writer->write_value( conv string( sy-uname ) ).
    writer->close_element( ).
    writer->open_element( name = 'date' ).
    writer->write_value( conv string( sy-datlo ) ).
    writer->close_element( ).
    writer->close_element( ).
    writer->open_element( name = 'body' ).
    DO 10 TIMES.
      CALL TRANSFORMATION id SOURCE number  = sy-index
                             RESULT XML writer.
    ENDDO.
    writer->close_element( ).
    writer->close_element( ).
    DATA(xml) =
      CAST cl_sxml_string_writer( writer )->get_output(  ).
    cl_demo_output=>display_xml( xml ).
  ENDMETHOD.
ENDCLASS.

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

Description

An XML writer is filled with XML data split into the parts head and body. The data content of the element body is taken directly from an internal table using the identity transformation ID.