The manakai project

Web::XPath::Parser

An XPath parser

SYNOPSIS

  use Web::XPath::Parser;
  $parser = Web::XPath::Parser->new;
  $parsed = $parser->parse_char_string_as_expression ('/child::a/child::b');

DESCRIPTION

The Web::XPath::Parser module contains an XPath parser, i.e. a processor to convert XPath string into its internal data structure representation.

METHODS

Following methods are available:

$parser = Web::XPath::Parser->new

Return a new instance of the parser.

$code = $parser->onerror
$parser->onerror ($new_code)

Get or set the error handler for the parser. Any parse error, as well as warning and information, is reported to the handler. See Whatpm::Errors <https://github.com/wakaba/manakai/blob/master/lib/Whatpm/Errors.pod> for more information.

$code = $parser->ns_resolver
$parser->ns_resolver ($new_code)

Get or set the namespace prefix resolver. It must be a code reference (or undef to unset). The code reference will be invoked with an argument, which is a character string representing the namespace prefix. The code reference must return a character string representing the namespace URL. The code reference must not throw an exception. It must return consistent result. Note that the null namespace cannot be represented.

If the namespace resolver is not specified, there is no namespace binding applicable to XPath expression parsing.

$vars = $parser->variable_bindings
$parser->variable_bindings ($vars)

Get or set the Web::XPath::VariableBindings object, containing the set of variable bindings used to parse XPath expressions.

$package = $parser->function_library
$parser->function_library ($package)

Get or set the package name of the function library used to parse the XPath expression. It must be a Perl package name string, which identifies Web::XPath::FunctionLibrary, its subclass, or equivalent. The module is required if necessary. See Web::XPath::FunctionLibrary for details.

$parsed = $parser->parse_char_string_as_expression ($string)

Parse the specified character string as an XPath 1.0 expression. If the parsing does not fail, it returns the parsed data structure. If the parsing fails, it reports the parse errors via the onerror handler and returns undef.

The parsed data structure can be used as input to Web::XPath::Evaluator.

The parser does not examine whether the input string does not contain non-Unicode character (i.e. U-00110000) for performance reason. If your application would like to fully conform to relevant standards, you have to ensure that the input does not contain any character greater than U+10FFFF before invoking the parser.

SEE ALSO

Web::XPath::Evaluator.

SPECIFICATIONS

XPATH1

XML Path Language (XPath) Version 1.0 <https://www.w3.org/TR/xpath/>.

XML Path Language (XPath) Version 1.0 Specification Errata <https://www.w3.org/1999/11/REC-xpath-19991116-errata/>.

If the tokenizer can't tokenize the entire input string, it MUST throw an syntax error and abort the parsing process.

In the Literal production rule, any Unicode code point (i.e. U+0000-U+10FFFF) MUST be allowed. (This is a willful violation to the XPath 1.0 specification for compatibility with browsers.)

The parser MUST resolve any namespace prefix in the input string. If the prefix cannot be resolved, it MUST throw a namespace error and abort the parsing process.

The empty string namespace URL MUST NOT be interpreted as the null namespace.

The parser MUST examine whether any variable reference in the input string references a variable included in the variable bindings of the context. If the variable is not found, it MUST throw a syntax error and abort the parsing process.

The parser MUST examine whether any function call in the input string idetifies a function included in the function library of the context. If the function is not defined, the number of arguments is less than the minimum number of acceptable arguments, or the number of argument is greater than the maximum number of acceptable arguments, then it MUST throw a syntax error and abort the parsing process.

AUTHOR

Wakaba <wakaba@suikawiki.org>.

LICENSE

Copyright 2013-2016 Wakaba <wakaba@suikawiki.org>.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.