And XML::LibXML version (its DOM), most important docs in XML::LibXML::Node/XML::LibXML::Element/XML::LibXML::AttributeHash
xpaths courtesy of xpather.pl #!/usr/bin/perl --
#~ 2014-03-10-19:28:00 by Anonymous Monk
#~ perltidy -csc -otr -opr -ce -nibc -i=4
#!/usr/bin/perl --
use strict; use warnings;
use XML::LibXML 1.70; ## for load_html/load_xml/location
use Data::Dump qw/ dd /;
my $shortxmlraw = q{<?xml version="1.0" encoding="utf-8"?> <ApiRespons
+e Status="OK" xmlns="http://api.namecheap.com/xml.response"> <Command
+Response Type="namecheap.domains.getList"> <DomainGetListResult> <Dom
+ain Expires="03/31/2015" ID="8888888" Name="Domain1.com"/> </DomainGe
+tListResult> </CommandResponse> </ApiResponse>};
my $xmlraw = q{<?xml version="1.0" encoding="utf-8"?>
<ApiResponse Status="OK" xmlns="http://api.namecheap.com/xml.response"
+>
<Errors />
<Warnings />
<RequestedCommand>namecheap.domains.getList</RequestedCommand>
<CommandResponse Type="namecheap.domains.getList">
<DomainGetListResult>
<Domain ID="8888888" Name="Domain1.com" Expires="03/31/2015"/>
<Domain ID="8888889" Name="Domain2.com" Expires="02/25/2015"/>
<Domain ID="8888899" Name="Domain3.com" Expires="04/01/2015"/>
<Domain ID="8888999" Name="Domain4.com" Expires="05/20/2015"/>
</DomainGetListResult>
<Paging>
<TotalItems>4</TotalItems>
<CurrentPage>1</CurrentPage>
<PageSize>50</PageSize>
</Paging>
</CommandResponse>
<Server>API02</Server>
<GMTTimeDifference>--5:00</GMTTimeDifference>
<ExecutionTime>0.008</ExecutionTime>
</ApiResponse>
};
my $doml = XML::LibXML->new( qw/ recover 2 / )->load_xml( string => $x
+mlraw );
my $doms = XML::LibXML->new( qw/ recover 2 / )->load_xml( string => $s
+hortxmlraw );
Shabba( $doml );
Shabba( $doms );
exit( 0 );
sub Shabba {
my( $dom ) = @_;
## this here xpath courtesy of xpather.pl
my $shabba = q{
/*[ name() = 'ApiResponse' ]
/*[ name() = 'CommandResponse' ]
/*[ name() = 'DomainGetListResult' ]
/*[ name() = 'Domain' ]
};
foreach my $domain ( $dom->findnodes( $shabba ) ) {
#~ foreach my $domain ( $dom->findnodes( q{ //*[ name() = 'Domain
+' ] } ) ) {
printf "%s %s %s\n",
$domain->{'ID'},
$domain->getAttribute('Expires'),
$domain->getAttribute('Name'),
;;;;;;
}
print "\n";
}
__END__
$ perl xml-simple-to-xml-libxml-1077492.pl
8888888 03/31/2015 Domain1.com
8888889 02/25/2015 Domain2.com
8888899 04/01/2015 Domain3.com
8888999 05/20/2015 Domain4.com
8888888 03/31/2015 Domain1.com
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|