1XML::LibXML::Pattern(3)User Contributed Perl DocumentatioXnML::LibXML::Pattern(3)
2
3
4

NAME

6       XML::LibXML::Pattern - XML::LibXML::Pattern - interface to libxml2
7       XPath patterns
8

SYNOPSIS

10         use XML::LibXML;
11         my $pattern = XML::LibXML::Pattern->new('/x:html/x:body//x:div', { 'x' => 'http://www.w3.org/1999/xhtml' });
12         # test a match on an XML::LibXML::Node $node
13
14         if ($pattern->matchesNode($node)) { ... }
15
16         # or on an XML::LibXML::Reader
17
18         if ($reader->matchesPattern($pattern)) { ... }
19
20         # or skip reading all nodes that do not match
21
22         print $reader->nodePath while $reader->nextPatternMatch($pattern);
23
24         $pattern = XML::LibXML::Pattern->new( pattern, { prefix => namespace_URI, ... } );
25         $bool = $pattern->matchesNode($node);
26

DESCRIPTION

28       This is a perl interface to libxml2's pattern matching support
29       http://xmlsoft.org/html/libxml-pattern.html. This feature requires
30       recent versions of libxml2.
31
32       Patterns are a small subset of XPath language, which is limited to
33       (disjunctions of) location paths involving the child and descendant
34       axes in abbreviated form as described by the extended BNF given below:
35
36         Selector ::=     Path ( '|' Path )*
37         Path     ::=     ('.//' | '//' | '/' )? Step ( '/' Step )*
38         Step     ::=     '.' | NameTest
39         NameTest ::=     QName | '*' | NCName ':' '*'
40
41       For readability, whitespace may be used in selector XPath expressions
42       even though not explicitly allowed by the grammar: whitespace may be
43       freely added within patterns before or after any token, where
44
45         token     ::=     '.' | '/' | '//' | '|' | NameTest
46
47       Note that no predicates or attribute tests are allowed.
48
49       Patterns are particularly useful for stream parsing provided via the
50       "XML::LibXML::Reader" interface.
51
52       new()
53             $pattern = XML::LibXML::Pattern->new( pattern, { prefix => namespace_URI, ... } );
54
55           The constructor of a pattern takes a pattern expression (as
56           described by the BNF grammar above) and an optional HASH reference
57           mapping prefixes to namespace URIs. The method returns a compiled
58           pattern object.
59
60           Note that if the document has a default namespace, it must still be
61           given an prefix in order to be matched (as demanded by the XPath
62           1.0 specification). For example, to match an element "<a
63           xmlns="http://foo.bar"</a>", one should use a pattern like this:
64
65             $pattern = XML::LibXML::Pattern->new( 'foo:a', { foo => 'http://foo.bar' });
66
67       matchesNode($node)
68             $bool = $pattern->matchesNode($node);
69
70           Given an XML::LibXML::Node object, returns a true value if the node
71           is matched by the compiled pattern expression.
72

SEE ALSO

74       XML::LibXML::Reader for other methods involving compiled patterns.
75

AUTHORS

77       Matt Sergeant, Christian Glahn, Petr Pajas
78

VERSION

80       2.0209
81
83       2001-2007, AxKit.com Ltd.
84
85       2002-2006, Christian Glahn.
86
87       2006-2009, Petr Pajas.
88

LICENSE

90       This program is free software; you can redistribute it and/or modify it
91       under the same terms as Perl itself.
92
93
94
95perl v5.38.0                      2023-07-21           XML::LibXML::Pattern(3)
Impressum