in reply to problem with using LibXML and namespace
#!/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 |