Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2018-03-23 23:47 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (297 votes). Check out past polls.