in reply to Some issues with WWW::Mechanize::Firefox->xpath() method

test_xpath($mech, 'substring(//p,1,4)', all => 1); # expected String: Hell

That is not valid xpath syntax, what documentation are you reading?

  • Comment on Re: Some issues with WWW::Mechanize::Firefox->xpath() method (xpath 1.0)

Replies are listed 'Best First'.
Re^2: Some issues with WWW::Mechanize::Firefox->xpath() method (xpath 1.0)
by choroba (Cardinal) on Apr 02, 2013 at 10:22 UTC
    Works for me (using XML::XSH2):
    $ xsh $scratch/> insert element p into /scratch $scratch/> insert text 'Hello world' into /scratch/p $scratch/> echo substring(//p,1,4) Hell
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      Works for me (using XML::XSH2):

      And you're sure that's not an xsh2 function/feature?

      Produces no output for me

      #!/usr/bin/perl -- use strict; use warnings; use XML::LibXML; my $html = <<'__HTML__'; <html> <head> <title>Hello Firefox!</title> </head> <body> <h1>Hello <b>World</b>!</h1> <p id='paragraph'>Hello <b>WWW::Mechanize::Firefox</b> Goob bye</p> </body> </html> __HTML__ my $dom = XML::LibXML->new( qw/ recover 2 / )->load_html( #~ string => \$html, ## BUG! scalar... not like load_xml string => $html, ); local $\ = $/; print for $dom->findnodes(q{ substring(//p,1,4) }); ## nada print for $dom->findnodes(q{ //p }); ## paragraph
        You are using findnodes, but there is no node corresponding to the substring. Use find instead:
        print for $dom->find(q{ substring(//p,1,4) });
        لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re^2: Some issues with WWW::Mechanize::Firefox->xpath() method (xpath 1.0)
by dfaure (Chaplain) on Apr 02, 2013 at 10:20 UTC
    That is not valid xpath syntax, what documentation are you reading?

    All comes from the specs (http://www.w3.org/TR/xpath/#section-Expressions) which I need to respect.

    ____
    HTH, Dominique
    My two favorites:
    If the only tool you have is a hammer, you will see every problem as a nail. --Abraham Maslow
    Bien faire, et le faire savoir...