In deep complex XML

S

sow

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?
 
S

sow

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.

so how can I change it
 
S

sow

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
 
M

Mumia W.

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.
 
S

sow

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
 
M

Mumia W.

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?
 

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

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,836
Latest member
login dogas

Latest Threads

Top