Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Namespaced XML::LibXML XPath query

by lestrrat (Deacon)
on Feb 16, 2006 at 12:19 UTC ( [id://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="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" ); }

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:
    $doc->findnodes('//myns:root/myns:stuff/myns:items/myns:book');
    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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-20 13:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found