Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: Parsing XML

by calebcall (Sexton)
on Mar 08, 2014 at 06:43 UTC ( [id://1077495]=note: print w/replies, xml ) Need Help??


in reply to Re: Parsing XML
in thread Parsing XML

Perfect! Thanks. So simple now that I see what you did, it works great.

Replies are listed 'Best First'.
Re^3: Parsing XML
by McA (Priest) on Mar 08, 2014 at 07:05 UTC

    You're welcome. But be aware, XML::Simple plays not nice sometimes. Change your xml file to the following and show what happens:

    <?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="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>

    You'll see your script dies.

    XML::Simple creates an array ref when it sees more than one element, but a simple hash ref when there is one.

    Instantiate you XML::Simple object this way to force that the one element is always handles as an array:

    my $result = $xml->XMLin("myouput.xml", ForceArray => ['Domain']);

    When you start learning XML handling modules have a look at XML::Twig.

    McA

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (2)
As of 2024-04-25 06:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found