Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Test::XML::XPath doesn't match

by Ovid (Cardinal)
on Aug 12, 2009 at 10:33 UTC ( #787899=note: print w/ replies, xml ) Need Help??


in reply to Test::XML::XPath doesn't match

As far as I can tell, Test::XML::XPath won't let you do this directly. I'm unsure why, but it seems like you really need to find a way to register the XHTML namespace. You'll hate this, but the following monkey patch should makes your test pass:

{ no warnings 'redefine'; sub Test::XML::XPath::XML::LibXML::new { my ($class,$xml) = @_; my $p = XML::LibXML->new; $p->line_numbers(1); my $document = $p->parse_string($xml) or croak("Could not parse XML: $xml"); my $xpc = XML::LibXML::XPathContext->new( $document->documentE +lement ); $xpc->registerNs( x => "http://www.w3.org/1999/xhtml" ); return bless { xpath => $xpc } => $class; } }

The caveat is that you have to now use the 'x' prefix with your xpaths.

Update:: This assume that you're using XML::LibXML (which I assume you are).

like_xpath $html, '/x:html', 'An XHTML document';


Comment on Re: Test::XML::XPath doesn't match
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://787899]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2015-07-04 16:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls