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:
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" ;
Can anybody help ? I searched how to make the parser namespace negligent but I didn't find. Thanks . J.

-- Nice photos of naked perl sources here !


In reply to XML::LibXML findnodes fails when using namespaces by jeteve

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.