3 XML::LibXML::Pattern - XML::LibXML::Pattern - interface to libxml2 XPath patterns
10 my $pattern = new XML::LibXML::Pattern('/x:html/x:body//x:div', { 'x' => 'http://www.w3.org/1999/xhtml' });
11 # test a match on a XML::LibXML::Node $node
13 if ($pattern->matchesNode($node)) { ... }
15 # or on a XML::LibXML::Reader
17 if ($reader->matchesPattern($pattern)) { ... }
19 # or skip reading all nodes that do not match
21 print $reader->nodePath while $reader->nextPatternMatch($pattern);
23 $pattern = XML::LibXML::Pattern->new( pattern, { prefix => namespace_URI, ... } );
24 $bool = $pattern->matchesNode($node);
28 This is a perl interface to libxml2's pattern matching support I<<<<<< http://xmlsoft.org/html/libxml-pattern.html >>>>>>. This feature requires recent versions of libxml2.
30 Patterns are a small subset of XPath language, which is limitted to
31 (disjunctions of) location paths involving the child and descendant axes in
32 abbreviated form as described by the extended BNF given below:
36 Selector ::= Path ( '|' Path )*
37 Path ::= ('.//' | '//' | '/' )? Step ( '/' Step )*
38 Step ::= '.' | NameTest
39 NameTest ::= QName | '*' | NCName ':' '*'
41 For readability, whitespace may be used in selector XPath expressions even
42 though not explicitly allowed by the grammar: whitespace may be freely added
43 within patterns before or after any token, where
47 token ::= '.' | '/' | '//' | '|' | NameTest
49 Note that no predicates or attribute tests are allowed.
51 Patterns are particularly useful for stream parsing provided via the C<<<<<< XML::LibXML::Reader >>>>>> interface.
57 $pattern = XML::LibXML::Pattern->new( pattern, { prefix => namespace_URI, ... } );
59 The constructor of a pattern takes a pattern expression (as described by the
60 BNF grammar above) and an optional HASH reference mapping prefixes to namespace
61 URIs. The method returns a compiled pattern object.
63 Note that if the document has a default namespace, it must still be given an
64 prefix in order to be matched (as demanded by the XPath 1.0 specification). For
65 example, to match an element C<<<<<< <a xmlns="http://foo.bar"</a> >>>>>>, one should use a pattern like this:
69 $pattern = XML::LibXML::Pattern->new( 'foo:a', { foo => 'http://foo.bar' });
72 =item matchesNode($node)
74 $bool = $pattern->matchesNode($node);
76 Given a XML::LibXML::Node object, returns a true value if the node is matched
77 by the compiled pattern expression.
86 L<<<<<< XML::LibXML::Reader >>>>>> for other methods involving compiled patterns.
101 2001-2007, AxKit.com Ltd.
103 2002-2006, Christian Glahn.
105 2006-2009, Petr Pajas.