Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Data Interfaces and Communication Interfaces →  ABAP and XML →  Class Libraries for XML →  iXML Library →  iXML Library, Examples 

iXML Library, Filter for Iterator

Filtered access to nodes in DOM using an iterator.

Other versions: 7.31 | 7.40 | 7.54

Source Code

REPORT demo_ixml_filter_iterator.

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.

    DATA(iterator) = document->create_iterator_filtered(
                      document->create_filter_and(
                        filter1 = document->create_filter_node_type(
                          node_types = if_ixml_node=>co_node_element )
                        filter2 = document->create_filter_name_ns(
                          name = 'item' ) ) ).

    DATA target_tab LIKE source_tab.
    DO.
      DATA(node) = iterator->get_next( ).
      IF node IS INITIAL.
        EXIT.
      ENDIF.
      APPEND node->get_value( ) TO target_tab.
    ENDDO.

    cl_demo_output=>display( target_tab ).
  ENDMETHOD.
ENDCLASS.

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

Description

XML data is created in asXML format using the identity transformation and XML data is written directly to an XML document in DOM representation. An iterator is created for the full document, associated with a filter. The filter is an "and" join between two filters and selects by node type and name. The iterator only returns the selected nodes.