[ABAP] XML-Dokument aufbauen / erstellen und rendern

TRY.
* Interface
    DATA(o_ixml) = cl_ixml=>create( ).

* Document
    DATA(o_doc) = o_ixml->create_document( ).

* Root definieren
    DATA(o_root) = o_doc->create_simple_element_ns( prefix = 'asx'
                                                    name = 'list'
                                                    parent = o_doc ).

* zwei Root-Element-Attribute hinzufügen
    o_root->set_attribute_ns( name =  'asx'
                              prefix = 'xmlns'
                              value = 'http://www.google.com/xml' ).

    o_root->set_attribute_ns( name =  'version'
                              value = '1.0' ).

* Node1 unterhalb Root definieren
    DATA(o_node1) = o_doc->create_simple_element_ns( prefix = 'asx'
                                                     name = 'names'
                                                     parent = o_root ).

* Node2 zur Node1 hinzufügen
    DATA(o_node2) = o_doc->create_simple_element_ns( name = 'name'
                                                     value = 'ABC'
                                                     parent = o_node1  ).

* XML-String generieren
    DATA: xml TYPE string.

    DATA(o_stream) = o_ixml->create_stream_factory( )->create_ostream_cstring( xml ).
    o_ixml->create_renderer( document = o_doc
                             ostream = o_stream )->render( ).

* Anzeige im Browser
    cl_abap_browser=>show_xml( xml_string = xml
                               title      = 'Test XML'
                               size       = cl_abap_browser=>large ).

  CATCH cx_root INTO DATA(e_text).
    WRITE: / e_text->get_text( ).
ENDTRY.