foreach my $node ( findnodes("records/record") ) {  

  do something ..

  my $foo = $node->findvalue("foo/text()");
  print $foo;
}

findnodes returns either a nodeset object or an list of nodes depending on 
whether its called in scalar or list context. In this example we are 
calling in list context so we get a list of nodes to cycle through.

If you are not working from the root node you may need to provide a 
context node eg.

foreach my $node ( $n->findnodes("records/record") ) {  
  do something ..
}


On Wed, 10 Jul 2002, Nigel Peck wrote:

> How would I go about iterating over a collection of elements, of the
> same name. e.g.
> 
> <records>
>     <record>
>         <foo></foo>
>         <bar></bar>
>     </record>
>     <record>
>         <foo></foo>
>         <bar></bar>
>     </record>
> .........
> </records>
> 
> I want to deal with each <record> in turn using XPathScript.
> 
> Thanks
> Nigel
> 
> 
> ITM Business Solutions
> Unit 4
> Nine Trees Trading Estate
> Morthen Road
> Rotherham
> S66 9JG
> 
> Reception
> Tel: 01709 703288
> Fax: 01709 701549
> 
> Help Desk
> Tel:01709 530424
> Fax: 01709 702159
> 
> CONFIDENTIALITY NOTICE: This message is intended only for the use of
> the individual or entity to which it is addressed, and may contain
> information that is privileged, confidential and exempt from disclosure
> under applicable law.
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to