Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: Namespaced XML::LibXML XPath query

by lestrrat (Deacon)
on Feb 16, 2006 at 12:19 UTC ( #530646=note: print w/replies, xml ) Need Help??

in reply to Namespaced XML::LibXML XPath query

This is probably what you want:

use XML::LibXML; use XML::LibXML::XPathContext; { my $xml = <<'XML'; <?xml version="1.0" standalone="yes"?> <sdnList xmlns=""> <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', ''); my $result = $xc->findvalue('//sdnList:lastName'); is( $result, "Hello world!", "Namespace" ); }

Replies are listed 'Best First'.
Re^2: Namespaced XML::LibXML XPath query
by chovy (Initiate) on Sep 17, 2008 at 22:43 UTC
    So what you're saying is my xpath needs to be written like this:
    Given the following:
    <root xmlns="http://goobar/xml" xmlns:myns="http://goobar/xml"> <stuff> <items> <book>XML Namespaces</book> </items> </stuff> </root>
    That is really an ugly xpath expression.
      blame the XML guys ;) default namespaces are just plain stupid.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (12)
As of 2016-10-25 13:59 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (320 votes). Check out past polls.