Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: XPATH problems

by ikegami (Pope)
on Jan 09, 2010 at 04:24 UTC ( #816446=note: print w/ replies, xml ) Need Help??


in reply to XPATH problems

use strict; use warnings; use XML::LibXML; my $doc1 = XML::LibXML->new->parse_file('wiki.html'); my $doc2 = XML::LibXML->new->parse_file('timeline.html'); my ($node1) = $doc1->findnodes('//div[@id="metanav"]'); my ($node2) = $doc2->findnodes('//div[@id="metanav"]'); $node1->replaceNode($node2); print $doc1->toString(0);

But the XPath you are using looks wrong. Don't you want to match {http://www.w3.org/1999/xhtml}div elements (i.e. XHTML div elements), not div elements with no namespace?

use strict; use warnings; use XML::LibXML; my $xpc = XML::LibXML::XPathContext->new; $xpc->registerNs('h', 'http://www.w3.org/1999/xhtml'); my $doc1 = XML::LibXML->new->parse_file('wiki.html'); my $doc2 = XML::LibXML->new->parse_file('timeline.html'); my ($node1) = $xpc->findnodes('//h:div[@id="metanav"]', $doc1); my ($node2) = $xpc->findnodes('//h:div[@id="metanav"]', $doc2); $node1->replaceNode($node2); print $doc1->toString(0);


Comment on Re: XPATH problems
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2015-07-04 00:10 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 (57 votes), past polls