View on GitHub

PDF-Tags-raku

Tagged PDF writer

[Raku PDF Project] / [PDF-Tags Module] / PDF::Tags :: XPath

class PDF::Tags::XPath

Tiny XPath like search/navigation evaluator

Synopsis

use PDF::Class;
use PDF::Tags;
use PDF::Tags::XPath;
my PDF::Class $pdf .= open: "t/pdf/write-tags.pdf";
my PDF::Tags $tags .= read: :$pdf;
my PDF::Tags::XPath $xpath = $tags.xpath-context();
say .name for $xpath.find('Document/L/LI[1]/*');
# -OR-
say .name for $tags.find('Document/L/LI[1]/*');
# -OR-
say .name for $tags<Document/L/LI[1]/*>;

Description

PDF::Tags::XPath is an XPath like evaluator used to search for or to navigate between nodes. It is used to handle the find and first method available on all nodes and the AT-KEY method available on parent nodes (objects of type PDF::Tags, PDF::Tags::Element and PDF::Tags::Mark).

It implements a subset of the XPath axes, functions and data-types and includes some extensions to accommodate specifics of the Tagged PDF format.

Axes

Examples:

$node.first('parent::*'); # locate parent node
$node.first('..'); # locate parent node
for $node.find('following-sibling::P') {...} # process following paragraphs

The following XPath Axes are supported:

Node Tests

Examples:

for $tags.find('//mark()') { ... }; # match all marked content references

Predicate Functions:

Examples:

for $elem.find('L/LI[first() or last()]') {...}; # first and last list items 
for $elem.find('L/LI[position() >= 3]') {... };  # third list item onward

Predicate Operators

Loosest to tightest: