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
Renders XML documents to DOM representation.
Other versions:
7.31 | 7.40 | 7.54
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.
source_tab = VALUE #( FOR j = 1 UNTIL j > 10
( ipow( base = 2 exp = j ) ) ).
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 the identity 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:
- A renderer is created for the full document and its method RENDER is executed, producing complete XML data.
- The method RENDER of the document object is executed, which again renders the full document and produces the same result.
- The method RENDER of the element NUMBERS is executed recursively, which writes only the element and its subelements to the output stream.
- The method RENDER of the element NUMBERS is executed non-recursively, which writes only the element (without its subelements) to the output stream.