Parsing XML into a Perl structure

Z

zzapper

Hi am XML newbie

This is the XML that is returned from a distant server, I can process
it with standard Perl to get the data I want, but I know I ought to be
able to use a Perl Module such as XML::Simple to dump into a Perl
structure automatically, except I can't get it to work.

My xml data is in

$xml= $ua->request($req)->as_string;

can anyone help?

<?xml version="1.0" encoding="utf-8"?>
<ServerTxnResponse xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://www.zzzyyyxxx.com">
<StdResponse>
<Ad1AvsResult />
<CvcResult />
<AuthResult>6</AuthResult>
<AuthCode>789DE</AuthCode>
....
</StdResponse>

--
zzapper

vim -c ":%s%s*%Cyrnfr)fcbafbe[Oenz(Zbbyranne%|:%s)[[()])-)Ig|norm Vg?"

http://www.rayninfo.co.uk/tips/ vim, zsh & life tips
 
Z

zzapper

Mike H said:
I've used XML::Simple, the only thing I believe I do is remove the
processing instructions which are your 1st 2 directives

<?xml version="1.0" encoding="utf-8"?>
<ServerTxnResponse xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://www.zzzyyyxxx.com">

use XML::Simple;
my $parser = XML::Simple->new();
my $doc = $parser->XMLin(.....something like that,

the XML::Simple documentation is.
Mike
With help from you I've succeeded with (it's the parameters for xmlin
which are crucial:-

$xml= $ua->request($req)->content;

my $parser = XML::Simple->new();
my $doc = $parser->XMLin($xml, forcearray => 1, keyattr => list);

print Dumper $doc;

--
zzapper

vim -c ":%s%s*%Cyrnfr)fcbafbe[Oenz(Zbbyranne%|:%s)[[()])-)Ig|norm Vg?"

http://www.rayninfo.co.uk/tips/ vim, zsh & life tips
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top