<?xml version="1.0" encoding="windows-1252"?>
<node id="530519" title="Namespaced XML::LibXML XPath query" created="2006-02-15 15:45:27" updated="2006-02-15 10:45:27">
<type id="115">
perlquestion</type>
<author id="194920">
diotalevi</author>
<data>
<field name="doctext">
&lt;p&gt;I am trying to perform a normal query into an XML document where something has been declared about the default namespace. If the &lt;c&gt;xmlns="..."&lt;/c&gt; part of the data is removed then this test succeeds. What needs to change in my XPath query &lt;c&gt;//lastName&lt;/c&gt; or [cpan://XML::LibXML] parser object so that this query will succeed?&lt;/p&gt;&lt;code&gt;use Test::More tests =&gt; 2;
use XML::LibXML ();

{
    my $xml = &lt;&lt;'XML';
&lt;?xml version="1.0" standalone="yes"?&gt;
&lt;sdnList&gt;
  &lt;sdnEntry&gt;
    &lt;lastName&gt;Hello world!&lt;/lastName&gt;
  &lt;/sdnEntry&gt;
&lt;/sdnList&gt;
XML
    my $parser = XML::LibXML-&gt;new;
    my $doc    = $parser-&gt;parse_string($xml);
    my $result = $doc-&gt;findvalue('//lastName');
    is( $result, "Hello world!", "No namespace" );
}
{
    my $xml = &lt;&lt;'XML';
&lt;?xml version="1.0" standalone="yes"?&gt;
&lt;sdnList xmlns="http://tempuri.org/sdnList.xsd"&gt;
  &lt;sdnEntry&gt;
    &lt;lastName&gt;Hello world!&lt;/lastName&gt;
  &lt;/sdnEntry&gt;
&lt;/sdnList&gt;
XML
    my $parser = XML::LibXML-&gt;new;
    my $doc    = $parser-&gt;parse_string($xml);
    my $result = $doc-&gt;findvalue('//lastName');
    is( $result, "Hello world!", "Namespace" );
}&lt;/code&gt;&lt;p&gt;Results&lt;/p&gt;&lt;code&gt;1..2
ok 1 - No namespace
not ok 2 - Namespace
#   Failed test 'Namespace'
#   in sdl2.pl at line 30.
#          got: ''
#     expected: 'Hello world!'
# Looks like you failed 1 test of 2.&lt;/code&gt;</field>
</data>
</node>
