xml::libxml::iterator(3)

NAME

XML::LibXML::Iterator - Simple Tree Iteration Class for
XML::LibXML

SYNOPSIS

use XML::LibXML;
use XML::LibXML::Iterator;
my $doc = XML::LibXML->new->parse_string( $somedata );
my $iter= XML::LibXML::Iterator->new( $doc );
$iter->iterator_function( iterate );
# more control on the flow
while ( $iter->next ) {
    # do something
}
# operate on the entire tree
$iter->iterate( operate );

DESCRIPTION

An iterator allows to operate on a document tree as it
would be a linear sequence of nodes.

Functions

new($first_node)
first()
next()
previous()
last()
current()
index()
iterator_function($funcion_ref);
iterate($function_ref);

XML::LibXML::Iterator knows two types of callback. One is
knows as the iterator function, the other is used by iter_
ate(). The first function will be called for each call of
next() or previous(). It is used to find out about the next node recognized by the iterator.

The iterator function has to take two parameters: As the
first parameter it will recieve the iterator object, as
second the direction of the iteration will be passed. The
direction is either 1 (for next()) or -1 (for previous()).

The iterators iterate() function will take a function ref erence that takes as well two parameters. The first param
eter is again the iterator object. The second parameter is
the node to operate on. The iterate function can do any
operation on the node as prefered. Appending new nodes or
removing the current node will not confuse the iteration
process: The iterator preloads the next object before
calling the iteration function. Thus the Iterator will not
find nodes appended by the iteration function.
Copyright © 2010-2025 Platon Technologies, s.r.o.           Home | Man pages | tLDP | Documents | Utilities | About
Design by styleshout