In deep complex XML

Discussion in 'Perl Misc' started by sow, Jul 22, 2007.

  1. sow

    sow Guest

    I have problem with get specific values from xml script below:

    $VAR1 = {
    'report_params' => {
    'customer_code' => 'name',
    'customer_id' => '123',
    'account_details' => [
    {
    'account_code' => 'account01',
    'state_code' => 'DELETED',
    'related_ani' => {
    'state_code' => 'DELETED',
    'phone_number' => '123456',
    'object_id' => '12',
    'subscription' => [
    {
    'valid_to' => '2007-07-17T13:42:46',
    'valid_from' => '2007-07-16T19:17:05',
    'service_type_code' => 'VoIP',
    'service_code' => 'serv01'
    },
    {
    'valid_to' => '2007-07-18T12:15:16',
    'session' => [
    {
    'currency_code' => 'QWE',
    'duration' => '0',
    'amount' => '0',
    },
    {
    'currency_code' => 'QWE',
    'duration' => '1313',
    'amount' => '-1.75',
    }
    ],
    'valid_from' => '2007-07-17T13:43:23',
    'service_type_code' => 'VoIP',
    'service_code' => 'serv02'
    },
    {
    'valid_to' => '2007-07-18T12:51:19',
    'valid_from' => '2007-07-18T12:47:51',
    'service_type_code' => 'VoIP',
    'service_code' => 'serv03'
    }
    ]
    },
    'created_date' => '2007-07-16T19:02:12'
    },
    {
    'account_code' => 'account02',
    'state_code' => 'ENABLED',
    'related_ani' => {
    'state_code' => 'ENABLED',
    'phone_number' => '123456',
    'object_id' => '13',
    'subscription' => [
    {
    'session' => [
    {
    'currency_code' => 'QWE',
    'duration' => '0',
    'amount' => '0',
    },
    {
    'currency_code' => 'QWE',
    'duration' => '150',
    'amount' => '-1.975',
    },
    {
    'currency_code' => 'SEC',
    'duration' => '101',
    'amount' => '-101',
    },
    {
    'currency_code' => 'SEC',
    'duration' => '616',
    'amount' => '-616',
    }
    ],
    'valid_from' => '2007-07-18T12:56:33',
    'service_type_code' => 'VoIP',
    'service_code' => 'serv04'
    }
    },
    'created_date' => '2007-07-18T12:52:47'
    }
    ],
    };

    and script in perl:

    #!/usr/bin/perl
    use XML::Simple;
    $xml = new XML::Simple;
    $data = $xml->XMLin($ARGV[0],
    KeyAttr => {account_details => 'account_code',subscription =>
    'service_code',session => 'currency_code'},
    ForceArray => 1,
    );

    foreach $e (@{$data->{account_details}->{account02}->
    {related_ani}->{subscription}->{serv04}->{session}->{QWE}})
    {
    printf "value %20s\n",$e->{amount};
    }

    and I've error:
    Pseudo-hashes are deprecated at ./script line 9.
    No such pseudo-hash field "account02" at ./billing2 line 9.

    Any advice?
    sow, Jul 22, 2007
    #1
    1. Advertising

  2. sow

    sow Guest

    On 22 Lip, 21:08, Eric Amick <> wrote:
    > On Sun, 22 Jul 2007 08:41:51 -0700, sow <> wrote:
    > >I have problem with get specific values from xml script below:

    >
    > >$VAR1 = {
    > > 'report_params' => {
    > > 'customer_code' => 'name',
    > > 'customer_id' => '123',
    > > 'account_details' => [
    > > {
    > > 'account_code' => 'account01',
    > > 'state_code' => 'DELETED',
    > > 'related_ani' => {
    > > 'state_code' => 'DELETED',
    > > 'phone_number' => '123456',
    > > 'object_id' => '12',
    > > 'subscription' => [
    > > {
    > > 'valid_to' => '2007-07-17T13:42:46',
    > > 'valid_from' => '2007-07-16T19:17:05',
    > > 'service_type_code' => 'VoIP',
    > > 'service_code' => 'serv01'
    > > },
    > > {
    > > 'valid_to' => '2007-07-18T12:15:16',
    > > 'session' => [
    > > {
    > > 'currency_code' => 'QWE',
    > > 'duration' => '0',
    > > 'amount' => '0',
    > > },
    > > {
    > > 'currency_code' => 'QWE',
    > > 'duration' => '1313',
    > > 'amount' => '-1.75',
    > > }
    > > ],
    > > 'valid_from' => '2007-07-17T13:43:23',
    > > 'service_type_code' => 'VoIP',
    > > 'service_code' => 'serv02'
    > > },
    > > {
    > > 'valid_to' => '2007-07-18T12:51:19',
    > > 'valid_from' => '2007-07-18T12:47:51',
    > > 'service_type_code' => 'VoIP',
    > > 'service_code' => 'serv03'
    > > }
    > > ]
    > > },
    > > 'created_date' => '2007-07-16T19:02:12'
    > > },
    > > {
    > > 'account_code' => 'account02',
    > > 'state_code' => 'ENABLED',
    > > 'related_ani' => {
    > > 'state_code' => 'ENABLED',
    > > 'phone_number' => '123456',
    > > 'object_id' => '13',
    > > 'subscription' => [
    > > {
    > > 'session' => [
    > > {
    > > 'currency_code' => 'QWE',
    > > 'duration' => '0',
    > > 'amount' => '0',
    > > },
    > > {
    > > 'currency_code' => 'QWE',
    > > 'duration' => '150',
    > > 'amount' => '-1.975',
    > > },
    > > {
    > > 'currency_code' => 'SEC',
    > > 'duration' => '101',
    > > 'amount' => '-101',
    > > },
    > > {
    > > 'currency_code' => 'SEC',
    > > 'duration' => '616',
    > > 'amount' => '-616',
    > > }
    > > ],
    > > 'valid_from' => '2007-07-18T12:56:33',
    > > 'service_type_code' => 'VoIP',
    > > 'service_code' => 'serv04'
    > > }
    > > },
    > > 'created_date' => '2007-07-18T12:52:47'
    > > }
    > > ],
    > > };

    >
    > >and script in perl:

    >
    > >#!/usr/bin/perl
    > >use XML::Simple;
    > >$xml = new XML::Simple;
    > >$data = $xml->XMLin($ARGV[0],
    > >KeyAttr => {account_details => 'account_code',subscription =>
    > > 'service_code',session => 'currency_code'},
    > >ForceArray => 1,
    > >);

    >
    > >foreach $e (@{$data->{account_details}->{account02}->
    > > {related_ani}->{subscription}->{serv04}->{session}->{QWE}})
    > >{
    > >printf "value %20s\n",$e->{amount};
    > >}

    >
    > >and I've error:
    > >Pseudo-hashes are deprecated at ./script line 9.
    > >No such pseudo-hash field "account02" at ./billing2 line 9.

    >
    > >Any advice?

    >
    > Dump the structure of $data after you construct it; I think you'll find
    > account02 is not a hash reference.
    > --
    > Eric Amick
    > Columbia, MD


    so how can I change it
    sow, Jul 22, 2007
    #2
    1. Advertising

  3. sow

    sow Guest

    And if I change
    ForceArray => 1 to
    ForceArray => ['account_details','subscription','session']
    I get:
    Not an ARRAY reference at ./billing2 line 9
    mabye is the other way how to get this values "amount" from xml using
    XML::Simle
    sow, Jul 22, 2007
    #3
  4. sow

    Mumia W. Guest

    On 07/22/2007 10:41 AM, sow wrote:
    > I have problem with get specific values from xml script below:
    >
    > $VAR1 = {
    > 'report_params' => {
    > 'customer_code' => 'name',
    > 'customer_id' => '123',
    > 'account_details' => [...]


    The data you posted does not compile for me. There is a missing bracket
    or brace somewhere.
    Mumia W., Jul 22, 2007
    #4
  5. sow

    sow Guest

    yes mabye I lost bracket due to shorten xml tree if somebody know well
    XML::Simple I'll sent original xml, I didn't want put the original
    because it was very long
    sow, Jul 23, 2007
    #5
  6. sow

    Mumia W. Guest

    On 07/22/2007 10:41 AM, sow wrote:
    > I have problem with get specific values from xml script below:
    > [ http://pastebin.mozilla.org/174383 * ]
    >
    > and script in perl:
    >
    > #!/usr/bin/perl
    > use XML::Simple;
    > $xml = new XML::Simple;
    > $data = $xml->XMLin($ARGV[0],
    > KeyAttr => {account_details => 'account_code',subscription =>
    > 'service_code',session => 'currency_code'},
    > ForceArray => 1,
    > );
    >
    > foreach $e (@{$data->{account_details}->{account02}->
    > {related_ani}->{subscription}->{serv04}->{session}->{QWE}})
    > {
    > printf "value %20s\n",$e->{amount};
    > }
    >
    > and I've error:
    > Pseudo-hashes are deprecated at ./script line 9.
    > No such pseudo-hash field "account02" at ./billing2 line 9.
    >
    > Any advice?
    >


    The ForceArray => 1 option is causing this. You seem to have written
    your code to not require ForceArray, but you use the option anyway.

    Read up on pseudo hashes in "perldoc perlref," and use Data::Dumper to
    check your hash again. No combination of options to XMLin() that I can
    figure allows for "serv04" to be a key under "subscription." The QWE
    element does not exist, and even if it did, would it be in uppercase?

    --
    * Sow sent the XML file to me in a private e-mail.
    Mumia W., Jul 23, 2007
    #6
    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. news.amnet.net.au
    Replies:
    1
    Views:
    570
    =?UTF-8?b?TMSByrtpZSBUZWNoaWU=?=
    Apr 13, 2004
  2. Stanimir Stamenkov
    Replies:
    2
    Views:
    740
    Stanimir Stamenkov
    Oct 25, 2005
  3. Robert Mark Bram
    Replies:
    0
    Views:
    679
    Robert Mark Bram
    Feb 4, 2007
  4. Kottiyath

    How complex is complex?

    Kottiyath, Mar 18, 2009, in forum: Python
    Replies:
    22
    Views:
    756
  5. sow

    In deep complex XML

    sow, Jul 22, 2007, in forum: Perl Misc
    Replies:
    0
    Views:
    70
Loading...

Share This Page