<p>i have tried to use the LibXML modules to xpath a document but its
getting complicated ..........
i have seen this example over forum here .........</p>
<code>
use XML::LibXML ;
use strict;
use warnings;
{
    my $xml = <<'XML';
<?xml version="1.0" standalone="yes"?>
<sdnList>
  <sdnEntry>
    <lastName>Hello world!</lastName>
  </sdnEntry>
</sdnList>
XML
    my $parser = XML::LibXML->new;
    my $doc    = $parser->parse_string($xml);
    my $result = $doc->findvalue('//lastName');
    print $result;
}
{
    my $xml = <<'XML';
<?xml version="1.0" standalone="yes"?>
<sdnList xmlns="http://tempuri.org/sdnList.xsd";>
  <sdnEntry>
    <lastName>Hello world!</lastName>
  </sdnEntry>
</sdnList>
XML
    my $parser = XML::LibXML->new;
    my $doc    = $parser->parse_string($xml);
    my $result = $doc->findvalue('//lastName');
    print $result ;
}
</code> /


One of the member posted this solution ... /

<code>
use XML::LibXML;
use XML::LibXML::XPathContext;

{
    my $xml = <<'XML';
<?xml version="1.0" standalone="yes"?>
<sdnList xmlns="http://tempuri.org/sdnList.xsd";>
  <sdnEntry>
    <lastName>Hello world!</lastName>
  </sdnEntry>
</sdnList>
XML
    my $parser = XML::LibXML->new;
    my $doc    = $parser->parse_string($xml);
    my $xc     = XML::LibXML::XPathContext->new($doc);
    $xc->registerNs('sdnList', 'http://tempuri.org/sdnList.xsd');
    my $result = $xc->findvalue('//sdnList:lastName');
    is( $result, "Hello world!", "Namespace" );
}
</code>
<p>
But every time we can't get same namespace ... if i add any API to the
xml input ..... its extremely difficult to handle it ...... </p>
<p>
Is there any way to get nodes and attr and like that stuff in
XML::LibXML easily ??? or any other modules excpet xml::xpath..</p>

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to