Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Data Interfaces and Communication Interfaces →  ABAP and XML →  Class Libraries for XML →  iXML Library →  iXML Library - Access to DOM →  iXML Library - DOM Reads 

iXML Library, Reads Using Iterators

The section Direct Read demonstrates how to access the DOM nodes directly using the following objects:

  • Objects with the IF_IXML_NODE interface for individual nodes
  • Objects with the IF_IXML_NODE_LIST interface for lists of subnodes
  • Objects with the IF_IXML_NODE_COLLECTION interface for lists of element names
  • Objects with the IF_IXML_NAMED_NODE_MAP interface for lists of attributes

An iterator can be created for each of these objects. This iterator makes it possible to iterate the DOM elements represented by the objects. The interface of every iterator provides the same options for accessing the objects iterated by the iterator.

Other versions: 7.31 | 7.40 | 7.54


Note

The iterators shown here are forward iterators that iterate from left to right or from top to bottom. The interfaces of the objects also make it possible to create backward iterators, which iterate from right to left or from bottom to top.

Iterator for Nodes

A reference variable document with the type IF_IXML_NODE, which points to an XML document, can be used to create an iterator for all the nodes of the document as follows:

DATA(iterator) = document->create_iterator( [depth] ).

The static type of the reference variable iterator is then IF_IXML_NODE_ITERATOR. This points to the iterator whose methods can iterate the nodes. The optional input parameter depth can be used to specify the depth of the nodes in the tree structure used for the iteration. To create an iterator for iterating the subnodes of a specific node, it is possible to use a reference variable node of type IF_IXML_NODE, instead of document. This reference variable point to a node object.

Iterator nodes can be iterated using the following method:

DATA(node) = iterator->get_next( ).

The static type of the reference variable node is then IF_IXML_NODE and it points to the object of the current iterator node. If no more nodes exist, node is initial.


Notes

  • Unlike a node direct read, which can be restricted to the elements of the representedXML data, an iterator captures all nodes in an XML document, including nodes that only contain structural information. Use the method GET_TYPE of interface IF_IXML_NODE to read the node type and compare it to constants of this interface. Filter or Down Casts provide further options for only selecting specified nodes.

  • Besides the iterator for subnodes shown here, an inline iterator is also available (with the interface IF_IXML_INLINE_ITERATOR) for iterating neighboring nodes.

Executable Example

Iterator for Nodes

Iterators for Lists

An iterator can be created for all of the lists under Direct Read

  • Node list (IF_IXML_NODE_LIST)
  • Element list (IF_IXML_NODE_COLLECTION)
  • Attribute list (IF_IXML_NAMED_NODE_MAP)

:

DATA(iterator) = nodes|elements|attributes->create_iterator( ).

In all three cases, the reference variable has the static type IF_IXML_NODE_ITERATOR and points to an iterator for the elements of the relevant list. This iterator can be used as shown above.


Note

As the lists only contain the required elements, it is usually not necessary to query the type (unlike when iterating the entire document or subtrees).

Executable Examples