XPath test #2

すいませんHTML::TreeBuilder::XPathの使い方間違ってました...
tree->findnodesじゃなくてtree->find_xpathして自分で結果のクラスをみる必要アリ。tree->findはいまいち結果が変だった(ちがったかも。細かいところは忘れた)。

substring-after("n13","n") は通るようになった。

os0xさんのTwitter / Shogo Ohta: substring-afterとかもちゃんと動いている...をふまえて

{context=>'',xpath=>q{substring-after("n13","n")},expected=>q{13}},
{context=>'',xpath=>q{(substring-after("n13","n"))},expected=>q{13}},
{context=>'',xpath=>q{(.//h1|.//h2|.//h3)[last()]},expected=>q{h3}},

いれてみたやつも問題なし。

descendantまわりにあるバグ意外は実用上問題なさそうです。
descendantの問題じゃなくてblockquoteの下にコメントノードがあるからそれでpositionがひとつずれて問題になってるっぽい。

  my $results = eval {
        #$tree->find_xpath($x, $body);
        $body->find_xpath($x);
    };

    if ( $@ ) {
        print "*xpath evaluation failed. $x\n";
        print "$@\n";
        next;
    }

    my $literal;

    if ( $results->isa('XML::XPathEngine::Number') ) {
        $literal = $results->string_value;
    } elsif ( $results->isa('XML::XPathEngine::Literal') ) {
        $literal = $results->string_value;
    } else {
        $literal = eval {
            join " ", map {
                $lastOne = $_ ;

                if ( $_->isa('HTML::TreeBuilder::XPath::TextNode') ) {
                    #if ( $_->isCommentNode ) {
                    #   'c:' . $_->getValue;
                    #} else {
                        't:' . $_->getValue;
                    #}
                } else {
                    $_->tag;
                }

            } @$results;
        };
    }
*ng .//blockquote/comment()
        expected: c:blockquoteComment
        result  :
*ng .//blockquote/processing-instruction()
        expected: p:pi
        result  :
*ng .//blockquote/processing-instruction("pi")
        expected: p:pi
        result  :
*ng .//blockquote/node()
        expected: c:blockquoteComment t:blockquoteText1: br t:blockquoteText2 p p:pi font
        result  : t:blockquoteText1: br t:blockquoteText2 p font
*ng .//blockquote/descendant::*[position() < 4]
        expected: br p del
        result  : br del ins
*xpath evaluation failed. id(.//font/@face)
Can't locate object method "look_down" via package "HTML::TreeBuilder::XPath::Attribute" at /Library/Perl/5.8.6/HTML/TreeBuilder/XPath.pm line 34.

*ng .//blockquote/descendant::*[4]
        expected: ins
        result  : p
*ng .//blockquote/descendant-or-self::*[4]
        expected: del
        result  : p
*ng .//blockquote/preceding::*[4]
        expected: strong
        result  : h1
*xpath evaluation failed. .//*[substring(.,2,1) = "u"]
substr outside of string at /Library/Perl/5.8.6/XML/XPathEngine/Function.pm line 248.

*xpath evaluation failed. .//*[substring(.,2) = "up"]
substr outside of string at /Library/Perl/5.8.6/XML/XPathEngine/Function.pm line 251.

*xpath evaluation failed. .//*[lang("it")]
axis axis_attribute not implemented [Can't locate object method "getNamespace" via package "HTML::TreeBuilder::XPath::Attribute" at /Library/Perl/5.8.6/XML/XPathEngine.pm line 182.
]