NAME

XML::Parser::Lite::Tree::XPath - XPath access to XML::Parser::Lite::Tree trees

SYNOPSIS

  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');

DESCRIPTION

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

METHODS

new($tree)

Returns an XML::Parser::Lite::Tree::XPath object for the given tree.

set_tree($tree)

Sets the tree for the object.

select_nodes($xpath)

Returns an array of nodes for the given XPath.

AXES

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

FUNCTIONS

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()

UNSUPPORTED FEATURES

In addition to the unsupported functions and axes, several XPath features are also unsupported.

  * attribute fetching
  * relative paths

CAVEATS

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()]).

AUTHOR

Copyright (C) 2004, Cal Henderson, <cal@iamcal.com>

SEE ALSO

XML::Parser::Lite XML::Parser::Lite::Tree http://www.w3.org/TR/xpath