Even though TIMTOWTDI, I prefer writing this

Hah, my way :)

over this

Well, you only really need the first one ... unless all of a sudden the xml switches the default namespace ... which makes for weak xml

because it's shorter, has less repetition, and uses the recommended API... the XPath stuff is already where it belongs: in an XPath expression context.

Yes, the completely unspecified part of the api that is up to each implementer to implement

To use the recommended API xpather.pl would have to switch to printing perl code instead of xpaths ....

With xpather.pl you copy/paste the xpaths, edit minimally , practically no writing involved :) and even the dumbest newbie can copy/paste (and xml/xpath not exactly newbie friendly)

FWIW , this is F2.0

$node->F("//f:p/g:h", qw[ f http://f.example.com g http://g.example.co +m ]); sub XML::LibXML::Node::F { my $self = shift; my $xpath = shift; my %prefix = @_; our $XPATHCONTEXT; $XPATHCONTEXT ||= XML::LibXML::XPathContext->new(); while( my( $p, $u ) = each %prefix ){ $XPATHCONTEXT->registerNs( $p, $u ); } $XPATHCONTEXT->findnodes( $xpath, $self ); }

In reply to Re^5: Xpath not working by Anonymous Monk
in thread Xpath not working by njack

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.