XML::Parser::Lite::Tree::XPath - XPath access to XML::Parser::Lite::Tree trees
use XML::Parser::Lite::Tree; use XML::Parser::Lite::Tree::XPath; my $xpath = new XML::Parser::Lite::Tree::XPath($tree); my @nodes = $xpath->select_nodes('/photoset/photos');
This module offers limited XPath functionality for XML::Parser::Lite::Tree objects. For more information about XPath see http://www.zvon.org/xxl/XPathTutorial/General/examples.html
XML::Parser::Lite::Tree
new($tree)
Returns an XML::Parser::Lite::Tree::XPath object for the given tree.
XML::Parser::Lite::Tree::XPath
set_tree($tree)
Sets the tree for the object.
select_nodes($xpath)
Returns an array of nodes for the given XPath.
The child axis is used by default. The following rules are equivilent:
/foo/bar /foo/child::bar
The following axes are supported:
ancestor ancestor-or-self child descendant descendant-or-self following following-sibling preceding preceding-sibling parent self
But these axes are not supported:
attribute namespace
Only a handful of the XPath functions are implemented. If you need further functions, send the author a test case and he'll try and implement them.
The following functions are supported:
last() not() normalize-space() count() name() starts-with() contains() position() string-length() floor() ceiling()
But these functions are not currently supported:
id() string() concat() substring_before() substring_after() substring() translate() boolean() true() false() lang() number() sum() round() x_lower() x_upper() generate_id()
In addition to the unsupported functions and axes, several XPath features are also unsupported.
* attribute fetching * relative paths
Sub-rules are evaluated in a boolean context, except in the case where a subrule is a simple integer (e.g. //foo[3]). This has some odd side effects - the last() function returns a boolean specifying whether the element is the last in the set or not. To get the sequence number of the last element in a set (e.g. //foo[position() = last()]), use the last-id() function instead. If you need to do some sort of caclulation which would return a position (e.g. //foo[1+1]), then compare the value using the position() function to get the correct result (e.g. //foo[1+1 = position()]).
//foo[3]
last()
//foo[position() = last()]
last-id()
//foo[1+1]
position()
//foo[1+1 = position()]
Copyright (C) 2004, Cal Henderson, <cal@iamcal.com>
XML::Parser::Lite XML::Parser::Lite::Tree http://www.w3.org/TR/xpath
To install XML::Parser::Lite::Tree::XPath, copy and paste the appropriate command in to your terminal.
cpanm
cpanm XML::Parser::Lite::Tree::XPath
CPAN shell
perl -MCPAN -e shell install XML::Parser::Lite::Tree::XPath
For more information on module installation, please visit the detailed CPAN module installation guide.