2016-09-27 126 views
0

我有以下脚本,显然这不会让我提交更多的细节。它基本上是由一个SOAP请求转换成XML拉动基本计划的细节,我需要从它.:检索值Perl肥皂请求检索一个值?

#!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; 

它输出:

<?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> [ 

我要严格到<message>部分的日期/时间说:

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

我该怎么做?

+0

你对Perl有多坚定?你自己修改了那个明显存在的脚本吗? – simbabque

回答

0

最实用的方法是将包含XML的原始结果作为字符串取出,并使用正则表达式对其进行解析。所有你想要的是一个固定模式,所以不需要实际使用XML解析器(或者SOAP :: Lite带来的内置东西)。

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

现在你有2017-09-29T21:18:20Z$date_string内,可以用它做你想要什么。

+0

感谢您的意见。我试着按照你的建议,当我打印$ date_string;它什么都不返回。 – John

+0

@约翰有一个'+'丢失。错在我身边,对不起。 – simbabque

+0

谢谢simbabque。在那里加号仍然没有喜悦。 – John