Rand Stats

XML::XPath

github:ufobat

XML::XPath

Build Status Build status

A Perl 6 Library for parsing and evaluating XPath Statements.

XPath Specification

Specification on XPath Expressions can be found at https://www.w3.org/TR/xpath/.

Synopsis

use XML::XPath;

my $xpath  = XML::XPath.new(xml => '... xml ...');
my $result = $xpath.find('/foo/bar');

Example

If you want to see more examples please have a look at the testcases.

Documentation

XML::XPath.new(:$file, :$xml, :$document)

XML::XPath creates a XML Document from a $file or from $xml unless you provide a $document in the constructor.

.find(Str $xpath, XML::Node :$start, Bool :$to-list)

Evaluates the XPath Expression and returns the results of the match. If a $start node is provided it starts there instead of beginning of the XML Document. If $to-list is True the result will allways be an Array, otherwise it might return Any or a single element (e.g XML::Node, Str, Nummeric, Bool)

.set-namespace(Pair $ns)

This method sets a namespace, so the value of $ns.key can be used in the XPath expression to look nodes a certain namespace.

$x.set-namespace: 'goo' => "foobar.example.com";
$set = $x.find('//goo:something');

.clear-namespaces

Clears all namespaces that have been set via .set-namespace.

.parse-xpath(Str $xpath)

Just parses $xpath expression.

License

Artistic License 2.0.