Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Which outputs: status: success subnet: 10.11.24.0 netmask: 255.255.255.0 gateway: 10.11.13.1 But I need to output ALL the routes defined not just the first. The XML received from the web service is formatted like so:use strict; use warnings; use Net::SSL(); BEGIN { $Net::HTTPS::SSL_SOCKET_CLASS = "Net::SSL"; $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0; $ENV{HTTPS_PROXY} = 'http://<proxyip>:<proxyport>'; } use LWP::UserAgent; use XML::Simple qw(:strict); #use XML::Simple; use Data::Dumper; my $url = 'https://<ip>:<port>/<webservice>?ip=10.11.13.10&ser +vers=10.7.11.7'; my $ua = LWP::UserAgent->new(); my $req = HTTP::Request->new('GET', $url); my $res = $ua->request($req); my $config = XMLin($res->content(), KeyAttr => { dict => 'key' }, + ForceArray => [ 'dict', 'value' ]); print "status: " , $config->{dict}->{status}->{value}->[0] , "\n"; print "subnet: " , $config->{dict}->{data}->{list}->{dict}->{subnet}- +>{value}->[0] , "\n"; print "netmask: " , $config->{dict}->{data}->{list}->{dict}->{netmask} +->{value}->[0] , "\n"; print "gateway: " , $config->{dict}->{data}->{list}->{dict}->{gateway} +->{value}->[0] , "\n";
<root> <dict key="status"> <value>success</value> </dict> <dict key="data"> <list> <dict key="subnet"> <value>10.11.14.0</value> </dict> <dict key="gateway"><value>10.11.13.1</value> </dict> <dict key="cidr"><value>10.11.14.0/21</value> </dict> <dict key="netmask"><value>255.255.248.0</value> </dict> <dict key="subnet"><value>10.11.15.0</value> </dict> <dict key="gateway"><value>10.11.13.1</value> </dict> <dict key="cidr"><value>10.11.15.0/24</value> </dict> <dict key="netmask"><value>255.255.255.0</value> </dict> <dict key="subnet"> <value>10.15.8.0</value> </dict> <dict key="gateway"> <value>10.11.13.1</value> </dict> <dict key="cidr"> <value>10.15.8.0/22</value> </dict> <dict key="netmask"> <value>255.255.252.0</value> </dict> <dict key="subnet"> <value>10.7.17.22</value> </dict> <dict key="gateway"> <value>10.11.13.1</value> </dict> <dict key="cidr"> <value>10.7.17.224/28</value> </dict> <dict key="netmask"> <value>255.255.255.240</value> </dict> <dict key="subnet"> <value>10.11.24.0</value> </dict> <dict key="gateway"> <value>10.11.13.1</value> </dict><dict key="cidr"> <value>10.11.24.0/24</value> </dict><dict key="netmask" ><value>255.255.255.0</value> </dict> </list> </dict> <dict key="exitCode"> <value>0</value> </dict> </root>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Struggling with XML
by runrig (Abbot) on Oct 05, 2012 at 16:03 UTC | |
|
Re: Struggling with XML
by choroba (Cardinal) on Oct 05, 2012 at 12:04 UTC | |
|
Re: Struggling with XML
by remiah (Hermit) on Oct 05, 2012 at 13:05 UTC | |
by agentorange (Sexton) on Oct 05, 2012 at 13:28 UTC | |
|
Re: Struggling with XML
by tobyink (Canon) on Oct 05, 2012 at 21:26 UTC | |
by tobyink (Canon) on Oct 08, 2012 at 12:58 UTC | |
by agentorange (Sexton) on Oct 08, 2012 at 13:21 UTC | |
by agentorange (Sexton) on Oct 08, 2012 at 11:18 UTC | |
by tobyink (Canon) on Oct 08, 2012 at 12:59 UTC |