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 (abbreviated)
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:

my $browser=LWP::UserAgent->new();
$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 have tried turning forcearray on and off and have
used some other parameters with no success. From the structure of the
data, this seems so simple. The XML is:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl"
href="https://testmachine/sdk/html/defaultStyle.xsl"?>
<sdk:device xmlns:sdk="urn:sdk.company.com"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:sdk.company.com
https://testmachine/sdk/xsd/sdk.xsd">
<id value="dd8bca809f8ac174:45febfc9:10907635a57:-7eba"/>
<hostname value="Cisco 2924A"/>
<administrativeIp value="10.100.1.12"/>
<make value="Cisco"/>
<model value="Catalyst Switch with CatIOS"/>
<deviceClass value="unidentified"/>
<systemMemory value=""/>
<flashMemory value=""/>
<osVersion value="10.1 and above"/>
<addressLine1 value=""/>
<addressLine2 value=""/>
<city value=""/>
<stateOrProvince value=""/>
<postalCode value=""/>
<country value=""/>
<assetId value=""/>
<comments value=""/>
<deviceStatus value="READY_FOR_BACKUP"/>
<lastAccessed value="Thu Jan 26 13:34:01 CST 2006"/>
<backupStatus value="BACK_UP_FAILED"/>
<lastChangeCaptured value="Dec 31, 1969 6:00:00 PM"/>
<lastReboot value="Dec 31, 1969 6:00:00 PM"/>
<backupEnabled value="true"/>
<startupRunningSynchronized value="Not Applicable"/>
<managedElement
xlink:href="https://testmachine/sdk/managedElement?id=dd8bca809f8ac174:45febfc9:10907635a57:-7eba"/>
<configs/>
</sdk:device>


Any tips would be greatly appreciated! Thanks, Mandy.
 
J

J. Gleixner

mhubbard said:
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 (abbreviated)
results of
print Dumper($XMLRef):

$VAR1 = {
'administrativeIp' => {
'value' => '10.100.1.12'
},
};

Here is my code:

my $browser=LWP::UserAgent->new();
$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 have tried turning forcearray on and off and have
used some other parameters with no success. From the structure of the
data, this seems so simple. The XML is:

What did you want to get, the value of 'value'? 10.100.1.12?

$deviceXML->{ 'administrativeIp' }{ 'value' }

You could also call Dumper to see what's in that hash:

print $deviceXML->{ 'administrativeIp' }
 
J

J. Gleixner

J. Gleixner said:
You could also call Dumper to see what's in that hash:

print $deviceXML->{ 'administrativeIp' }

Might work a little better actually calling the method..

print Dumper( $deviceXML->{ 'administrativeIp' } );
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top