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