Parsing XML into a Perl structure

Discussion in 'XML' started by zzapper, Sep 29, 2004.

  1. zzapper

    zzapper Guest

    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
     
    zzapper, Sep 29, 2004
    #1
    1. Advertising

  2. zzapper

    Mike H Guest

    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.


    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 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, Sep 30, 2004
    #2
    1. Advertising

  3. zzapper

    zzapper Guest

    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 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.
    >
    >
    > 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 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
    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
     
    zzapper, Sep 30, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. impulse()
    Replies:
    0
    Views:
    2,549
    impulse()
    Oct 13, 2006
  2. Jason
    Replies:
    2
    Views:
    635
    Jason
    Apr 28, 2007
  3. Dale
    Replies:
    3
    Views:
    178
  4. Erik Wasser
    Replies:
    5
    Views:
    483
    Peter J. Holzer
    Mar 5, 2006
  5. banker123

    Perl Complex Data Structure Parsing

    banker123, Dec 3, 2006, in forum: Perl Misc
    Replies:
    4
    Views:
    182
    Alan_C
    Dec 5, 2006
Loading...

Share This Page