Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

XML::XPath Question

7 views
Skip to first unread message

Konstantinos Agouros

unread,
Nov 26, 2011, 4:31:47 AM11/26/11
to
Hi,

I would like to do a relative search on a subtree.

Say I got a NodeCollection doing something like:

$list = $xmlpath->find("/a/b")

Now I iterate about all instances of <b> in the document and for each one
I want to find the c's that have attribute foo.

so I do a foreach my $bar ($list->get_nodelist)
{
...
}

can I do a $bar->find("c[@foo]") or how can I do this relative to the
subtree of each b?

Regards,

Konstantin
--
Dipl-Inf. Konstantin Agouros aka Elwood Blues. Internet: elw...@agouros.de
Altersheimerstr. 1, 81545 Muenchen, Germany. Tel +49 89 69370185
----------------------------------------------------------------------------
"Captain, this ship will not survive the forming of the cosmos." B'Elana Torres

Ben Morrow

unread,
Nov 26, 2011, 6:30:55 AM11/26/11
to

Quoth Konstantinos Agouros <elw...@agouros.de>:
>
> I would like to do a relative search on a subtree.
>
> Say I got a NodeCollection doing something like:
>
> $list = $xmlpath->find("/a/b")
>
> Now I iterate about all instances of <b> in the document and for each one
> I want to find the c's that have attribute foo.
>
> so I do a foreach my $bar ($list->get_nodelist)
> {
> ...
> }
>
> can I do a $bar->find("c[@foo]") or how can I do this relative to the
^ ^
careful...
> subtree of each b?

You want

my $clist = $xmlpath->find('./c[@foo]', $bar);

or './/c[@foo]' if you want indirect as well as direct descendents.

Ben

Konstantinos Agouros

unread,
Nov 27, 2011, 3:41:08 AM11/27/11
to
Thanks!
0 new messages