Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

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="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" ); }


Comment on Re: Namespaced XML::LibXML XPath query
Download Code
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
Node Status?
node history
Node Type: note [id://530646]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (9)
As of 2014-12-28 00:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls