SAP NetWeaver AS ABAP Release 740, ©Copyright 2014 SAP AG. All rights reserved.
ABAP Keyword Documentation → ABAP − Reference → Data Interfaces and Communication Interfaces → ABAP and XML → Class Libraries for XML → iXML Library → iXML Library, Examples →iXML Library, Render
Render XML documents in DOM representation.
Source Code
REPORT demo_ixml_render.
CLASS ixml_demo DEFINITION.
PUBLIC SECTION.
CLASS-METHODS main.
ENDCLASS.
CLASS ixml_demo IMPLEMENTATION.
METHOD main.
DATA source_tab TYPE TABLE OF i.
DO 10 TIMES.
APPEND ipow( base = 2 exp = sy-index ) TO source_tab.
ENDDO.
DATA(ixml) = cl_ixml=>create( ).
DATA(document) = ixml->create_document( ).
CALL TRANSFORMATION id SOURCE text = `Powers of 2`
numbers = source_tab
RESULT XML document.
DO 7 TIMES.
document->find_from_name_ns( name = 'item' )->remove_node( ).
ENDDO.
DATA(out) = cl_demo_output=>new(
)->begin_section(
`Renderer for complete document` ).
DATA xml_string TYPE string.
ixml->create_renderer( document = document
ostream = ixml->create_stream_factory(
)->create_ostream_cstring(
string = xml_string )
)->render( ).
out->write_xml( xml_string )->line( ).
out->next_section(
`Method render for complete document` ).
CLEAR xml_string.
document->render( ostream = ixml->create_stream_factory(
)->create_ostream_cstring(
string = xml_string ) ).
out->write_xml( xml_string )->line( ).
out->next_section(
`Method render for subnode recursive` ).
CLEAR xml_string.
document->find_from_name_ns( name = 'NUMBERS'
)->render( ostream = ixml->create_stream_factory(
)->create_ostream_cstring(
string = xml_string )
recursive = abap_true ).
out->write( xml_string )->line( ).
out->next_section(
`Method render of subnode not recursive` ).
CLEAR xml_string.
document->find_from_name_ns( name = 'NUMBERS'
)->render( ostream = ixml->create_stream_factory(
)->create_ostream_cstring(
string = xml_string )
recursive = abap_false ).
out->display( xml_string ).
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
ixml_demo=>main( ).
Description
XML data is created in asXML format using an XSL transformation and written directly to an XML document in DOM representation. The method REMOVE_NODE is used to remove nodes and the content of the modified document is rendered in various ways: