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
In reply to Parsing XML by calebcall
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |