John John - 2 months ago 19
Perl Question

Perl soap request retrieving one value?

I have the following script that apparently this will not let me submit with more detail. It basically is pulling basic scheduling details from a SOAP request into XML and i need to retrieve a value from it.:

#!perl
#
# Quick sample script to fetch data from Tribune's Data Direct Service
#
# R. Eden 2/23/08
# (modified from XMLTV's tv_grab_na_dd, which started with a sample)
# script provided by Tribune

use SOAP::Lite;
use strict;

my $USER='username';
my $PASS='password';
my $START='2016-09-27T00:00:00Z';
my $STOP ='2016-09-27T23:59:59Z';

#
# Set login credientials
#
sub SOAP::Transport::HTTP::Client::get_basic_credentials {
return lc($USER) => "$PASS";
}


#
# Deifne SOAP service
#
my $dd_service='http://dd.schedulesdirect.org/tech/tmsdatadirect/schedulesdirect/tvDataDelivery.wsdl';
my $proxy='http://localhost/';
my $soap= SOAP::Lite
-> service($dd_service)
-> outputxml('true')
-> proxy($proxy, options => {compress_threshold => 10000,
timeout => 420});

#
# It's polite to set an agent string
#
$soap->transport->agent("perl/$0");


#
# Now let's get our data
#
my $raw_data=$soap->download($START,$STOP);


print $raw_data;

exit 0;





It outputs:

<?xml version='1.0' encoding='utf-8'?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:SOAP-ENC='http://schemas.xmlsoap.org/soap/encoding/'>
<SOAP-ENV:Body><ns1:downloadResponse SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' xmlns:ns1='urn:TMSWebServices'>
<xtvdResponse xsi:type='ns1:xtvdResponse'>

<messages xsi:type='ns1:messages'>

<message>Your subscription will expire: 2017-09-29T21:18:20Z</message>

</messages>
<xtvd from='2016-09-27T00:00:00Z' to='2016-09-27T23:59:59Z' schemaVersion='1.3' xmlns='urn:TMSWebServices' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='urn:TMSWebServices http://dd.schedulesdirect.org/tech/xml/schemas/tmsxtvd.xsd'>

<stations>
</stations>
<lineups>
</lineups>
</xtvd>
</xtvdResponse>
</ns1:downloadResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope> [





I strictly want to date/time of the part that says:

Your subscription will expire: 2017-09-29T21:18:20Z

How do I do that?

Thanks.

Answer

The most pragmatic way would be to just take the raw result that contains the XML as a string, and parse it with a regular expression. All you want is a fixed pattern, so there is no need to actually use an XML parser (or the built-in stuff that SOAP::Lite brings).

$raw_data =~ m/Your subscription will expire: ([^<]+)</;
my $date_string = $1;

Now you have 2017-09-29T21:18:20Z inside of $date_string and can do with it what you want.