Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Parsing XML into a Perl structure

Reply
Thread Tools

Parsing XML into a Perl structure

 
 
zzapper
Guest
Posts: n/a
 
      09-29-2004
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 xmlnssd="http://www.w3.org/2001/XMLSchema"
xmlnssi="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
 
Reply With Quote
 
 
 
 
Mike H
Guest
Posts: n/a
 
      09-30-2004
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 xmlnssd="http://www.w3.org/2001/XMLSchema"
xmlnssi="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.


On 29 Sep 2004 14:31:24 -0700, (zzapper) wrote:

>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 xmlnssd="http://www.w3.org/2001/XMLSchema"
>xmlnssi="http://www.w3.org/2001/XMLSchema-instance"
>xmlns="https://www.zzzyyyxxx.com">
> <StdResponse>
> <Ad1AvsResult />
> <CvcResult />
> <AuthResult>6</AuthResult>
> <AuthCode>789DE</AuthCode>
> ....
> </StdResponse>


 
Reply With Quote
 
 
 
 
zzapper
Guest
Posts: n/a
 
      09-30-2004
Mike H <> wrote in message news:<>. ..
> 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 xmlnssd="http://www.w3.org/2001/XMLSchema"
> xmlnssi="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.
>
>
> On 29 Sep 2004 14:31:24 -0700, (zzapper) wrote:
>
> >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 xmlnssd="http://www.w3.org/2001/XMLSchema"
> >xmlnssi="http://www.w3.org/2001/XMLSchema-instance"
> >xmlns="https://www.zzzyyyxxx.com">
> > <StdResponse>
> > <Ad1AvsResult />
> > <CvcResult />
> > <AuthResult>6</AuthResult>
> > <AuthCode>789DE</AuthCode>
> > ....
> > </StdResponse>

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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Parsing XML input from web form into namespaced xml file Jason XML 2 04-28-2007 12:41 AM
Perl Complex Data Structure Parsing banker123 Perl Misc 4 12-05-2006 06:31 AM
Parsing XML into PHP to insert into a MySQL DB impulse() XML 0 10-13-2006 03:05 PM
Different results parsing a XML file with XML::Simple (XML::Sax vs. XML::Parser) Erik Wasser Perl Misc 5 03-05-2006 10:09 PM
Parsing Path Data into Tree Structure Dale Perl Misc 3 05-01-2004 07:35 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57