Re: [xml] Another XML::LibXML Perl Question



On Fri, Jun 15, 2001 at 12:04:17AM -0700, dhogan wrote:
I need to iterate over the DOM in a serial manner.  Is there a built in
way for me to do this.
I see an XML::LibXML::Node:iterator method but no docos and I cant
figure out if that is what I need to do or not.

probably. the node::itertor function takes a function reference, which
is called for the node and all its child nodes. the function should 
take only a sinlge parameter, which will be the current node. 

example:
$node->iterator( sub { warn $_[0]->getName(); } );
warns all node names in a tree.

if each peice of XML where stored in an element of an array I would do
it like this.


foeach $thing (@xml) {
...
}

you can do this:
foreach $node ( $parent->getChildNodes() ) {
 ...
}

or

foreach $node ( $parent->getElementsByTagName( $tagname ) ) {
 ...
}


i hope this helps

christian




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]