Code: Alles auswählen.
DATA it_itab TYPE STANDARD TABLE OF mara.
SELECT * FROM mara INTO TABLE it_itab UP TO 10 ROWS.
DATA(o_writer_itab_xml) = cl_sxml_string_writer=>create( type = if_sxml=>co_xt_xml10 ).
CALL TRANSFORMATION id SOURCE values = it_itab RESULT XML o_writer_itab_xml.
DATA(itab_xml) = cl_abap_codepage=>convert_from( o_writer_itab_xml->get_output( ) ).
* ixml Factory
DATA(o_ixml) = cl_ixml=>create( ).
* DOM Object Model
DATA(o_doc) = o_ixml->create_document( ).
* XML-Dokument rendern
DATA(o_sf) = o_ixml->create_stream_factory( ).
* Encoding UTF-8
DATA(o_encoding) = o_ixml->create_encoding( character_set = 'UTF-8'
byte_order = if_ixml_encoding=>co_none ).
* Stream für Ausgabe in Datei '/tmp/test/test.xml' auf dem Applikationsserver
DATA(o_stream) = o_sf->create_ostream_uri( system_id = '/tmp/test/test.xml' ).
o_stream->set_encoding( encoding = o_encoding ).
o_stream->set_pretty_print( pretty_print = abap_true ).
* Render-Objekt
DATA(o_render) = o_ixml->create_renderer( ostream = o_stream
document = o_doc ).
* XML-String in Datei auf Applikationsserver generieren
DATA(lv_rc) = o_render->render( ).
* Dateigröße in Bytes
DATA(lv_size) = o_stream->get_num_written_raw( ).
* Stream schließen
o_stream->close( ).
Code: Alles auswählen.
DATA it_material_master_records TYPE STANDARD TABLE OF mara.
SELECT * FROM mara INTO TABLE it_material_master_records UP TO 10 ROWS.
DATA(o_writer_itab_xml) = cl_sxml_dataset_writer=>create( filename = '/tmp/test/test.xml' ).
CALL TRANSFORMATION id SOURCE values = it_material_master_records RESULT XML o_writer_itab_xml.
o_writer_itab_xml->close( ).
Code: Alles auswählen.
SELECT * FROM mara INTO TABLE it_material_master_records UP TO 10 ROWS.
DATA(o_ixml) = cl_ixml=>create( ).
DATA(o_document) = o_ixml->create_document( ).
CALL TRANSFORMATION id SOURCE values = it_material_master_records RESULT XML o_document.
DATA(o_sf) = o_ixml->create_stream_factory( ).
* Encoding UTF-8
DATA(o_encoding) = o_ixml->create_encoding( character_set = 'UTF-8'
byte_order = if_ixml_encoding=>co_none ).
* Stream für Ausgabe in Datei '/tmp/test/test.xml' auf dem Applikationsserver
DATA(o_stream) = o_sf->create_ostream_uri( system_id = '/tmp/test/test.xml' ).
o_stream->set_encoding( encoding = o_encoding ).
o_stream->set_pretty_print( pretty_print = abap_true ).
* Render-Objekt
DATA(o_render) = o_ixml->create_renderer( ostream = o_stream
document = o_document ).
* XML-String in Datei auf Applikationsserver generieren
DATA(lv_rc) = o_render->render( ).
* Dateigröße in Bytes
DATA(lv_size) = o_stream->get_num_written_raw( ).
* Stream schließen
o_stream->close( ).
Hallo jocoder,jocoder hat geschrieben: ↑03.02.2021 12:59Es gibt 2 Arten von XML-Bibliotheken:
1. SXML
2. IXML
Beide werden hier gemischt, was nicht notwendig ist.
Mit der SXML-Bibliothek und ohne Pretty-Print kann das Programm deutlich schlanker gestaltet werden:Mit der IXML sieht es dann wie folgt aus:Code: Alles auswählen.
DATA it_material_master_records TYPE STANDARD TABLE OF mara. SELECT * FROM mara INTO TABLE it_material_master_records UP TO 10 ROWS. DATA(o_writer_itab_xml) = cl_sxml_dataset_writer=>create( filename = '/tmp/test/test.xml' ). CALL TRANSFORMATION id SOURCE values = it_material_master_records RESULT XML o_writer_itab_xml. o_writer_itab_xml->close( ).
Code: Alles auswählen.
SELECT * FROM mara INTO TABLE it_material_master_records UP TO 10 ROWS. DATA(o_ixml) = cl_ixml=>create( ). DATA(o_document) = o_ixml->create_document( ). CALL TRANSFORMATION id SOURCE values = it_material_master_records RESULT XML o_document. DATA(o_sf) = o_ixml->create_stream_factory( ). * Encoding UTF-8 DATA(o_encoding) = o_ixml->create_encoding( character_set = 'UTF-8' byte_order = if_ixml_encoding=>co_none ). * Stream für Ausgabe in Datei '/tmp/test/test.xml' auf dem Applikationsserver DATA(o_stream) = o_sf->create_ostream_uri( system_id = '/tmp/test/test.xml' ). o_stream->set_encoding( encoding = o_encoding ). o_stream->set_pretty_print( pretty_print = abap_true ). * Render-Objekt DATA(o_render) = o_ixml->create_renderer( ostream = o_stream document = o_document ). * XML-String in Datei auf Applikationsserver generieren DATA(lv_rc) = o_render->render( ). * Dateigröße in Bytes DATA(lv_size) = o_stream->get_num_written_raw( ). * Stream schließen o_stream->close( ).