Re: Retrieving a node list
Brought to you by:
bs_php,
nigelswinson
|
From: Peter R. <php...@pe...> - 2003-03-17 11:15:28
|
On Sunday 16 Mar 2003 02:33, Eric Anderson wrote:
> I am having
> trouble figuring out how to do a XPath query and get back a list of
> nodes. So for example if I have a XML file as follows:
>
> <root>
> <tag>item1</tag>
> <tag>item2</tag>
> <tag>item3</tag>
> </root>
>
> I want to be able to say something like:
>
> $xPath = new XPath();
> $xPath->importFromFile( $filename );
> $list = $xPath->find( '/root/tag' );
> foreach ($list as $item) {
> echo $item->getText() . '<br>';
> }
replace 'find' with 'evaluate' (or 'match') and 'getText' with
'getData' and that should do what you're looking for (though you
might want to change your location path to e.g. //tag to fetch all
the descendant nodes)
|