Question

Locked

Problem while reading XML

By ravi.shankar ·
Dear All :
I have an XML file like :

=========================================================
<?xml version="1.0"?>
<gateway>
<version>Kannel bearerbox version `1.4.0'.
Build `Mar 1 2005 10:23:13', compiler `3.3.2 20031022 (Red Hat Linux 3.3.2-1)'.
System Linux, release 2.4.22-1.2199.nptl, version #1 Wed Aug 4 12:21:48 EDT 2004, machine i686.
Hostname s4.myvaluefirst.com, IP 207.234.209.215.
Libxml version 2.6.6.
Using OpenSSL 0.9.7a Feb 19 2003.
Compiled with MySQL 4.0.22, using MySQL 4.0.22.
Using native malloc.
</version>
<status>running, uptime 8d 22h 23m 24s</status>
<wdp>
<received><total>0</total><queued>0</queued></received>
<sent><total>0</total><queued>0</queued></sent>
</wdp>

<sms>
<received><total>799295</total><queued>0</queued></received>
<sent><total>41777</total><queued>457</queued></sent>
<storesize>-1</storesize>
<inbound>1.04</inbound>
<outbound>0.05</outbound>

</sms>
<dlr>
<queued>31981</queued>
<storage>internal</storage>
</dlr>
<boxes>
<box>
<type>smsbox</type>

<id></id>
<IP>127.0.0.1</IP>
<queue>0</queue>
<status>on-line 8d 22h 22m 33s</status>
<ssl>no</ssl>
</box><box>
<type>smsbox</type>

<id></id>
<IP>127.0.0.1</IP>
<queue>0</queue>
<status>on-line 2d 22h 38m 24s</status>
<ssl>no</ssl>
</box></boxes>
<smscs><count>5</count>

<smsc>
<name>SMPP:61.8.156.50:7667/7667:ganesh:smpp</name>
<id>rsms1</id>
<status>re-connecting</status>
<received>0</received>
<sent>0</sent>

<failed>0</failed>
<queued>0</queued>
</smsc>
<smsc>
<name>SMPP:59.145.173.82:4576/4576:valuefrst:smpp</name>
<id>spice</id>
<status>re-connecting</status>

<received>9801</received>
<sent>41777</sent>
<failed>5</failed>
<queued>0</queued>
</smsc>
<smsc>
<name>SMPP:202.56.254.87:11612/11612:ValueFirst:vnin</name>

<id>airtelb</id>
<status>online 5541s</status>
<received>3770</received>
<sent>0</sent>
<failed>0</failed>
<queued>0</queued>

</smsc>
<smsc>
<name>SMPP:202.56.254.87:11612/11612:VFirst:smpp</name>
<id>airtelb1</id>
<status>online 5540s</status>
<received>358666</received>
<sent>0</sent>

<failed>0</failed>
<queued>0</queued>
</smsc>
<smsc>
<name>SMPP:202.56.254.87:11612/11612:ValueF:smpp</name>
<id>airtelb2</id>
<status>online 5541s</status>

<received>150</received>
<sent>0</sent>
<failed>0</failed>
<queued>0</queued>
</smsc>
</smscs>
</gateway>
======================================================

And after parsing this XML using CPAN

I am getting the an array like this

======================================================
$VAR1 = {
'smscs' => {
'count' => '5',
'smsc' => {
'SMPP:202.56.254.87:11612/11612:VFirst:smpp' => {
'status' => 'online 5699s',
'id' => 'airtelb1',
'sent' => '0',
'received' => '358876',
'failed' => '0',
'queued' => '0'
},
'SMPP:59.145.173.82:4576/4576:valuefrst:smpp' => {
'status' => 're-connecting',
'id' => 'spice',
'sent' => '41777',
'received' => '9801',
'failed' => '5',
'queued' => '0'
},
'SMPP:61.8.156.50:7667/7667:ganesh:smpp' => {
'status' => 're-connecting',
'id' => 'rsms1',
'sent' => '0',
'received' => '0',
'failed' => '0',
'queued' => '0'
},
'SMPP:202.56.254.87:11612/11612:ValueF:smpp' => {
'status' => 'online 5700s',
'id' => 'airtelb2',
'sent' => '0',
'received' => '150',
'failed' => '0',
'queued' => '0'
},
'SMPP:202.56.254.87:11612/11612:ValueFirst:vnin' => {
'status' => 'online 5700s',
'id' => 'airtelb',
'sent' => '0',
'received' => '3771',
'failed' => '0',
'queued' => '0'
}
}
},
'sms' => {
'inbound' => '1.04',
'storesize' => '-1',
'outbound' => '0.05',
'sent' => {
'total' => '41777',
'queued' => '458'
},
'received' => {
'total' => '799506',
'queued' => '0'
}
},
'dlr' => {
'storage' => 'internal',
'queued' => '31981'
},
'status' => 'running, uptime 8d 22h 26m 3s',
'version' => 'Kannel bearerbox version `1.4.0\'.
Build `Mar 1 2005 10:23:13\', compiler `3.3.2 20031022 (Red Hat Linux 3.3.2-1)\'.
System Linux, release 2.4.22-1.2199.nptl, version #1 Wed Aug 4 12:21:48 EDT 2004, machine i686.
Hostname s4.myvaluefirst.com, IP 207.234.209.215.
Libxml version 2.6.6.
Using OpenSSL 0.9.7a Feb 19 2003.
Compiled with MySQL 4.0.22, using MySQL 4.0.22.
Using native malloc.
',
'boxes' => {
'box' => [
{
'ssl' => 'no',
'status' => 'on-line 8d 22h 25m 12s',
'IP' => '127.0.0.1',
'queue' => '0',
'id' => {},
'type' => 'smsbox'
},
{
'ssl' => 'no',
'status' => 'on-line 2d 22h 41m 3s',
'IP' => '127.0.0.1',
'queue' => '0',
'id' => {},
'type' => 'smsbox'
}
]
},
'wdp' => {
'sent' => {
'total' => '0',
'queued' => '0'
},
'received' => {
'total' => '0',
'queued' => '0'
}
}
};

=====================================================
I have made a script to read this XML file

like

=====================================================

#!/usr/bin/perl

# use module
use XML::Simple;

# create object
$xml = new XML::Simple;

#dump XML
system('rm /root/perlscript/kannel');
system ('/usr/bin/perl /root/perlscript/openkannel > /root/perlscript/kannel');

# read XML file
$data = $xml->XMLin("kannel");

# access XML data

print"$data->{smscs}->{smsc}->{hash_ref}->[2]->{name}";

print"\nTotal is : $data->{sms}->{received}->{total}\n";
print"\nStatus is : $data->{boxes}->{box}->{status}\n";

#print"\n$data->{version}";

print"\nTotal SMS received : $data->{sms}->{storesize}\n";

print"\nTotal SMS : $data->{smscs}->{smsc}->{hash_ref}->{id}";


===================================================
but I am getting error like

Bad index while coercing array into hash at ./checkkannel line 21.


can any one tell me how can I read and print following lines of array.


'SMPP:202.56.254.87:11612/11612:VFirst:smpp' => {
'status' => 'online 5699s',
'id' => 'airtelb1',
'sent' => '0',
'received' => '358876',
'failed' => '0',
'queued' => '0'
},


Thanks And Regards
Ravi Shankar

This conversation is currently closed to new comments.

2 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Share your knowledge
Back to Storage Forum
2 total posts (Page 1 of 1)  

Related Discussions

Related Forums