模式编译在 LibXML.pm 失败
Compilation of pattern failed at LibXML.pm
我正在使用 XML::LibXML
读取大型 HTML 文件。
构建这样的模式时:
XML::LibXML::Pattern->new('//span[@class="entry"]');
它给出了以下错误:
Compilation of pattern failed at /Users/chris/perl5/perlbrew/perls/perl-5.31.3/lib/site_perl/5.31.3/darwin-2level/XML/LibXML.pm line 2138.
但是这个工作正常:
XML::LibXML::Pattern->new('//span');
我不确定 [@class="entry"]
部分是否不受 XML::LibXML::Pattern
支持,或者我只是做错了。
如有任何信息,我们将不胜感激。提前致谢。
虽然是有效的 XPath,但它不是有效的 Pattern。
Patterns are a small subset of XPath language, which is limited to (disjunctions of) location paths involving the child and descendant axes in abbreviated form as described by the extended BNF given below:
Selector ::= Path ( '|' Path )*
Path ::= ('.//' | '//' | '/' )? Step ( '/' Step )*
Step ::= '.' | NameTest
NameTest ::= QName | '*' | NCName ':' '*'
For readability, whitespace may be used in selector XPath expressions even though not explicitly allowed by the grammar: whitespace may be freely added within patterns before or after any token, where
token ::= '.' | '/' | '//' | '|' | NameTest
Note that no predicates or attribute tests are allowed.
(强调我的。)
我正在使用 XML::LibXML
读取大型 HTML 文件。
构建这样的模式时:
XML::LibXML::Pattern->new('//span[@class="entry"]');
它给出了以下错误:
Compilation of pattern failed at /Users/chris/perl5/perlbrew/perls/perl-5.31.3/lib/site_perl/5.31.3/darwin-2level/XML/LibXML.pm line 2138.
但是这个工作正常:
XML::LibXML::Pattern->new('//span');
我不确定 [@class="entry"]
部分是否不受 XML::LibXML::Pattern
支持,或者我只是做错了。
如有任何信息,我们将不胜感激。提前致谢。
虽然是有效的 XPath,但它不是有效的 Pattern。
Patterns are a small subset of XPath language, which is limited to (disjunctions of) location paths involving the child and descendant axes in abbreviated form as described by the extended BNF given below:
Selector ::= Path ( '|' Path )* Path ::= ('.//' | '//' | '/' )? Step ( '/' Step )* Step ::= '.' | NameTest NameTest ::= QName | '*' | NCName ':' '*'
For readability, whitespace may be used in selector XPath expressions even though not explicitly allowed by the grammar: whitespace may be freely added within patterns before or after any token, where
token ::= '.' | '/' | '//' | '|' | NameTest
Note that no predicates or attribute tests are allowed.
(强调我的。)