I am not very experienced with perl and hashes.
I was looking for some help with displaying values from a SOAP request that returns XLM.
I have used the XMLin function to parse the XML, but I don't understand the syntax to display individual elements, and perhaps to list them all. I can see the data that I want in the structure using dumper. (some output included below)
Thanks for your help:
#!/usr/bin/perl
#use strict;
use LWP::UserAgent;
use XML::Simple;
use XML::Parser;
use Data::Dumper;
# this is the RPC call:
$xml_file = '<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.or
+g/soap/encoding/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/so
+ap/encoding/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-insta
+nce"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" x
+mlns:xsd="http://www.w3.org/1999/XMLSchema" >
<SOAP-ENV:Header xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oa
+sis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:Security SOAP-ENC:root="1">
<wsse:UsernameToken>
<wsse:Username xsi:type="xsd:string"><Removed></wsse:Username>
<wsse:Password xsi:type="xsd:string"><Removed></wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:retrieveTrafficStats xmlns:ns1="http://service.stats.ws.waas.cisc
+o.com" SOAP-ENC:root="1">
<name><removed></name>
<objType>wae</objType>
<trafficType>optimized</trafficType>
<direction>outbound</direction>
<timeframe> <startTime xsi:type="xsd:string">2010-09-27T12:00:00</star
+tTime>
<endTime xsi:type="xsd:string">2010-09-27T14:00:00</endTime>
<frequency xsi:type="xsd:string">lasthour</frequency>
<timezone xsi:type="xsd:string">utc</timezone>
</timeframe>
</ns1:retrieveTrafficStats>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>';
my $server = '<removed>';
my $port = '8443';
my $RPCPath = '/ws/TrafficStats';
my $uri = 'https://' . $server . ':' . $port . $RPCPath;
my $ua = LWP::UserAgent->new;
# we need to authenticate the https connection:
$ua->credentials( "", "TrafficStats", "admin", "default" );
$ua->ssl_opts("verify_hostname" =>"0");
my $header = HTTP::Headers->new;
$header->header('SOAPAction' => '"retrieveTrafficStats"');
# this is to define what SOAP RPC call we are making
my $request = HTTP::Request->new("POST",$uri,$header );
$request->content($xml_file);
my $response = $ua->request($request);
print $response->content;
my $output = new XML::Simple();
#my $output = new XML::Parser(Style => 'Debug');
$xmlout = $response->content;
$result=$output->XMLin($xmlout);
print "result dumper\n";
print Dumper($result);
print "result dumper\n";
--------------
dumper output:
$VAR1 = {
'soapenv:Body' => {
'ns:retrieveTrafficStatsResponse' => {
'xmlns:ns' => '
http://service.stats.ws.waas.cisco.com',
'xmlns:ax27' =>
'http://stats.ws.waas.cisco.com/xsd',
'xmlns:ax24' =>
'http://rmi.java/xsd',
'xmlns:ax26' =>
'http://util.ws.waas.cisco.com/xsd',
'xmlns:ax25' =>
'http://io.java/xsd',
'ns:return' =>
[
{
'ax27:passthroughotherin' => '18831',
'ax27:frequency' => 'min',
'ax27:passthroughpolicyin' => '63309241',
'ax27:passthroughoverloadout' => '-1',
'type' => 'com.cisco.waas.ws.stats.TrafficStats',
'ax27:passthroughpolicyout' => '164244598',
'ax27:passthroughintermediateout' => '122180531',
'ax27:compressedin' => '391370667',
'ax27:deviceName' => '<removed>',
'ax27:applicationname' => 'All Traffic',
'ax27:endtime' => '2015-04-30T07:59:17.304Z',
'ax27:compressedout' => '864063076',
'ax27:passthroughintermediatein' => '24109685',
'ax27:uncompressedout' => '535554446',
'ax27:passthroughpeerin' => '0',
'ax27:passthroughpeerout' => '0',
'ax27:starttime' => '2015-04-30T07:54:17.256Z',
'ax27:uncompressedin' => '1413828417',
'ax27:passthroughotherout' => '49179',
'ax27:passthroughoverloadin' => '-1'
},
{
'type' => 'com.cisco.waas.ws.stats.TrafficStats',
'ax27:passthroughoverloadout' => '-1',
'ax27:passthroughpolicyin' => '71192344',
'ax27:passthroughotherin' => '22382',
'ax27:frequency' => 'min',
'ax27:deviceName' => '<removed>',
'ax27:passthroughpolicyout' => '169230011',
'ax27:passthroughintermediateout' => '126671655',
'ax27:compressedin' => '370427975',
'ax27:uncompressedout' => '544864065',
'ax27:compressedout' => '1130966047',
'ax27:endtime' => '2015-04-30T07:54:17.256Z',
'ax27:applicationname' => 'All Traffic',
'ax27:passthroughintermediatein' => '31383318',
'ax27:passthroughotherout' => '52600',
'ax27:passthroughoverloadin' => '-1',
'ax27:passthroughpeerin' => '0',
'ax27:passthroughpeerout' => '0',
'ax27:uncompressedin' => '1797753870',
'ax27:starttime' => '2015-04-30T07:49:17.209Z'
},
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.