Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re: No bonus points for you :-)by tobyink (Canon) |
on Mar 22, 2013 at 16:46 UTC ( [id://1024960]=note: print w/replies, xml ) | Need Help?? |
Well, that would break XPath spec compliance. As per the XPath spec, node names with no colon always reference nodes with no namespace at all. Otherwise, if you could somehow set "gt" to be the default namespace for XPaths, you wouldn't be able to distinguish between the following two attributes:
I enjoy golf as much as the next man, but is three characters per name really so bad? (You could always bind the namespace to just "g" so it was two characters.) I saved you having to construct XML::LibXML::XPathContext objects, didn't I?? If your XPaths are fairly simple, you could take a look at XML::LibXML::QuerySelector which allows you to select nodes using CSS selectors. I wrote it for use with (X)HTML, but I don't see any reason it shouldn't roughly work with arbitrary XML.
package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name
In Section
Seekers of Perl Wisdom
|
|