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

Re: problem with using LibXML and namespace

by un-chomp (Scribe)
on Oct 26, 2007 at 17:05 UTC ( [id://647439]=note: print w/replies, xml ) Need Help??


in reply to problem with using LibXML and namespace

If you register the namespace using XML::LibXML::XPathContext you can then use XPaths to select nodes as follows:
#!/usr/bin/perl use strict; use warnings; use XML::LibXML; use XML::LibXML::XPathContext; # load the XML doc my $p = XML::LibXML->new; my $xml_file = do { local $/; <DATA> }; my $dom = $p->parse_string( $xml_file ); # register the namespace my $xc = XML::LibXML::XPathContext->new( $dom ); $xc->registerNs('ns', 'http://www.mydomain.com'); # select using XPath my @nodes = $xc->findnodes( '/ns:info/ns:city'); print $_->toString for @nodes; __DATA__ <?xml version="1.0"?> <info xmlns="http://www.mydomain.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mydomain.com infoschema.xsd"> <name>john</name> <city>baltimore</city> <zip>21205</zip> </info>

Replies are listed 'Best First'.
Re^2: problem with using LibXML and namespace
by mjr1n1 (Initiate) on Oct 26, 2007 at 17:48 UTC
    Thanks un-chomp. It's working now. mjr.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2024-04-23 19:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found