从SOAP :: Lite Response Hash中提取CDATA中的特定XML元素 [英] Extract specific XML element in CDATA taken from SOAP::Lite Response Hash
问题描述
下面的代码正在连接到.asmx Web服务以获取数据。
My code below is connecting to a .asmx web service to get data.
代码将CDATA提取到下面的%keyHash中。
The code extractes the CDATA into %keyHash below.
不是解析整个CDATA,而是可以通过调用SOAP CDATA的路径来获取特定数据元素吗?
Rather than parsing the entire CDATA, is it possible to grab a specific data element in the SOAP CDATA by calling out it's path?
我读到可以使用$ soap-> valueof()来获取数据,对吗?并且这将需要使用XPATH?
I read that I could use $soap->valueof() to get the data, is that correct? and that this would require use of XPATH?
我不熟悉这个问题,我不知道自己是否走对了,还有其他方法吗?
I ask as I am unfamiliar with this and I do not know if I am on the right path, are there other ways to do this?
我的$ soap-> valueof('// Images / Front')尝试失败,说我第一次使用XPATH可能会出错,但是此时我正在猜测是否这是正确的方法。
My $soap->valueof('//Images/Front') attempts have failed, saying that, my first time using XPATH, could be getting it wrong but at this point I am guessing if this is the right way to go.
任何关于我使用valueof()的正确或错误路径的指导都将受到赞赏!
Any direction on whether I am on the right or wrong path in using valueof() would be appreciated!
代码在这里,可以正常工作。我还包括从%keyHash中提取的模糊CDATA数据。
Here is the code, it works. I have also included the obscurated CDATA data extracted from %keyHash.
use SOAP::Lite +trace => 'all';
$soap = SOAP::Lite
-> uri('..../')
-> on_action( sub { join '/', '.....', $_[1] } )
-> proxy('......asmx');
$method = SOAP::Data->name('methodName')
->attr({xmlns => ...../'});
@params = (
SOAP::Data->name(tran=> 765) ->type(''),
SOAP::Data->name(token => 0)->type(''),
SOAP::Data->name(type=> 1)->type('')
);
%keyHash = %{ $soap->call($method => @params)->body->{'GetmethodNameResponse'}->{'GetmethodNameResult'} };
# iterate through all fields and print them
foreach my $k (keys %keyHash) {
print "$k=$keyHash{$k}\n";
}
数据输出示例,我希望字符串 THIS_IS_THE_DATA_I_WANT中的数据(由于某种原因,无法在此处放置路径)
Example of the data output, I want the data in the string "THIS_IS_THE_DATA_I_WANT" (unable to put the path here for some reason)
RequestResult=0
Xml=<?xml version="1.0" encoding="utf-8"?>
<Images>
<Front>THIS_IS_THE_DATA_I_WANT</Front>
</Images>
谢谢,
A
推荐答案
我通过使用以下代码解决了这个问题,希望它可以帮助某人...
I solved this by using the following, hope it helps someone...
use XML::Simple;
%keyhash = %{ $soap->call($method => @params)->body->{'GetCheckXmlResponse'}->{'GetCheckXmlResult'}};
$getxml= %keyhash->{Xml};
$parsexml = XMLin($getxml);
print Dumper($parsexml); # Use this to point to your data and then grab it as per the line below
$frontside = $parsexml->{Images}->{Front};
这篇关于从SOAP :: Lite Response Hash中提取CDATA中的特定XML元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!