Need Help Using XML::Simple

M

mhubbard

Hello all,
I have been able to get several examples of XML::Simple working, but
this one thing keeps tripping me up. Here are the results of
print Dumper($XMLRef):

$VAR1 = {
'lastChangeCaptured' => {
'value' => 'Dec 31, 1969 6:00:00 PM'
},
'backupEnabled' => {
'value' => 'true'
},
'model' => {
'value' => 'Catalyst Switch with CatIOS'
},
'startupRunningSynchronized' => {
'value' => 'Not Applicable'
},
'lastReboot' => {
'value' => 'Dec 31, 1969 6:00:00 PM'
},
'hostname' => {
'value' => 'Cisco 2924A'
},
'xmlns:xlink' => 'http://www.w3.org/1999/xlink',
'comments' => {
'value' => ''
},
'backupStatus' => {
'value' => 'BACK_UP_FAILED'
},
'city' => {
'value' => ''
},
'assetId' => {
'value' => ''
},
'flashMemory' => {
'value' => ''
},
'id' => {
'value' =>
'dd8bca809f8ac174:45febfc9:10907635a57:-7eba'
},
'xmlns:sdk' => 'urn:sdk.company.com',
'administrativeIp' => {
'value' => '10.100.1.12'
},
};

Here is my code:

$response = $browser->get($URL);
if(!($response->is_success)){
print "FAILED _getDeviceByIP - Unable to get device\n";
}else{
my $XML = $response->content;
my $deviceXML = XMLin($XML, forcearray=>1);

When I try to access $deviceXML->{administrativeIp}, I get
HASH(0x2228754).
 
P

Paul Lalli

mhubbard said:
I have been able to get several examples of XML::Simple working, but
this one thing keeps tripping me up. Here are the results of
print Dumper($XMLRef):

There is no $XMLRef variable in your code below. Did you mean
$deviceXML ?
$VAR1 = {
'administrativeIp' => {
'value' => '10.100.1.12'
},
};

Here is my code:

$response = $browser->get($URL);
if(!($response->is_success)){
print "FAILED _getDeviceByIP - Unable to get device\n";
}else{
my $XML = $response->content;
my $deviceXML = XMLin($XML, forcearray=>1);

When I try to access $deviceXML->{administrativeIp}, I get
HASH(0x2228754).

I agree. The Data::Dumper output you listed pretty clearly shows that
the value of the administrativelp key is a reference to a hash. That
hash has one key/value pair. The key is 'value' and the value is
'10.100.1.12'.
So you should be accessing $deviceXML->{administrativelp}{value}

Paul Lalli
 

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,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top