ARTICLE
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
You can create an iterator for each of these objects. This iterator
allows you 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.
Note
The iterators shown here are forward iterators that iterate from left to
right or from top to bottom. The objects interfaces also allow you to
create backwards 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. Using the optional
input parameter depth , you can specify the depth of the nodes in
the tree structure that you want to iterate. To create an iterator for
iterating the subnodes of a specific node, you can 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 are available,
then node is initial.
Notes
Unlike a node direct read ,
which can be restricted to the elements of the represented XML
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.
Example
See 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).
Examples
See:
Iterator for node list
Iterator for element list
Iterator for attributes
Documentation extract taken from SAP system, � Copyright SAP AG. All rights reserved