jeteve has asked for the wisdom of the Perl Monks concerning the following question:
Hi fellow monks.
I'm using XML::LibXML to edit xml files but I'm stucked to this problem:
When the root element of my document has an xmlns attributes, the findnodes method fails to give me the node I want.
Here is a test code:Can anybody help ? I searched how to make the parser namespace negligent but I didn't find. Thanks . J.use XML::LibXML ; my $xml = q{<?xml version="1.0" encoding="iso-8859-1"?> <Tag1 xmlns="wow"> <Foo>content</Foo> </Tag1> }; my $xml2 = q{<?xml version="1.0" encoding="iso-8859-1"?> <Tag1> <Foo>content</Foo> </Tag1> }; my $parser = XML::LibXML->new(); my $doc1 = $parser->parse_string($xml); my ($foo) = $doc1->findnodes('/Tag1/Foo'); print "Foo in xml: ".$foo."\n"; ## Gives undef (with xmlns) my $doc2 = $parser->parse_string($xml2); my ($foo2) = $doc2->findnodes('/Tag1/Foo'); ## IS OK (without xmlns) print "Foo in xml2: ".$foo2->textContent()."\n" ;
-- Nice photos of naked perl sources here !
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: XML::LibXML findnodes fails when using namespaces
by gellyfish (Monsignor) on Jun 13, 2006 at 12:31 UTC | |
Re: XML::LibXML findnodes fails when using namespaces
by tomhukins (Curate) on Jun 13, 2006 at 15:41 UTC |
Back to
Seekers of Perl Wisdom