Parsing XML into a Perl structure

zzapper

Usenet Archive
Joined
Sep 12, 2003
Messages
63
Reaction score
0
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>
 

Mike H

Usenet Archive
Joined
Oct 13, 2000
Messages
29
Reaction score
0

zzapper

Usenet Archive
Joined
Sep 12, 2003
Messages
63
Reaction score
0
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;
 

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
548,208
Messages
3,104,799
Members
249,594
Latest member
henrywalsh

Latest Threads

Top