Hi A complete Perl newbie and have started as looking at Perl and XML this week as have a requirement to access data via a web service and am struggling a little. Can anyone assist? My code:
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";
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:
<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>

In reply to Struggling with XML by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.