calebcall has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to parse some XML. I've been searching for some tutorials, reading perldocs, trying to find examples but can't find anything that's quite what I need. I'm trying to query namecheap.com's api to get a list of my domains and the date they expire. An example of how it outputs is:
<?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>
I've tried many things, but I think I'm close with the following:
#!/usr/bin/env perl use XML::Simple; use Data::Dumper; $xml = new XML::Simple; $result = $xml->XMLin("myouput.xml"); foreach my $domain (@{$result->{DomainGetListResult}}) { print $domain->{DomainGetListResult}->{Domain}->{Name} . "\n"; }
However, this returns nothing. I can use Data Dumper and dump out my $result and it gives me the info posted above (but in a hash). So I know it's getting the data. Just how do I specify the nested values? Do I start at the farthest out? (in this case ApiResponse?)
I'm also not opposed to using something other than XML::Simple if there is a module that is easier to use or better suited to what I am trying to do.
Any help would be appreciated. Thanks
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Parsing XML
by McA (Priest) on Mar 08, 2014 at 06:40 UTC | |
by calebcall (Sexton) on Mar 08, 2014 at 06:43 UTC | |
by McA (Priest) on Mar 08, 2014 at 07:05 UTC | |
by calebcall (Sexton) on Mar 11, 2014 at 01:53 UTC | |
by tangent (Parson) on Mar 11, 2014 at 02:06 UTC | |
by calebcall (Sexton) on Mar 11, 2014 at 04:27 UTC | |
by Anonymous Monk on Mar 11, 2014 at 02:42 UTC | |
by Anonymous Monk on Mar 11, 2014 at 02:20 UTC | |
by calebcall (Sexton) on Mar 11, 2014 at 04:29 UTC | |
Re: Parsing XML
by kcott (Archbishop) on Mar 08, 2014 at 07:01 UTC | |
Re: Parsing XML
by choroba (Cardinal) on Mar 11, 2014 at 09:02 UTC | |
Re: Parsing XML
by Discipulus (Canon) on Mar 11, 2014 at 08:58 UTC |