我从不同的SOAP方法获取数据。举个例子:
$wsdl = 'the_url_of_wsdl';
$client = new SoapClient($wsdl);
$parameters = array(all_the_parameters_inside);
$values = $client->the_method($parameters);
$xml = $values->the_methodResult->any;
$sxml = simplexml_load_string($xml);
$wsdl2 = 'the_url2_of_wsdl';
$client2 = new SoapClient($wsdl2);
$parameters2 = array(all_the_parameters_inside);
$values2 = $client->the_method2($parameters2);
$xml2 = $values2->the_method2Result->any;
$sxml2 = simplexml_load_string($xml2);
$wsdl3 = 'the_url3_of_wsdl';
$client3 = new SoapClient($wsdl3);
$parameters3 = array(all_the_parameters_inside);
$values3 = $client->the_method3($parameters3);
$xml3 = $values3->the_method3Result->any;
$sxml3 = simplexml_load_string($xml3);
如果我print_r $ sxml,$ sxml2和$ sxml3,我可以获取任何数据,让我们说
echo $sxml->name;
,echo $sxml2->id;
和echo $sxml3->description;
。
棘手的部分是这些值来自不同的方法,所以如何将它们组合在同一个HTML结构的循环中,所以就像这样:
<div class="article">
<div class="name">the value from the first method</div>
<div class="id">the value from the second method</div>
<div class="description">the value from the third method</div>
</div>
<div class="article">
<div class="name">the value from the first method</div>
<div class="id">the value from the second method</div>
<div class="description">the value from the third method</div>
</div>
<div class="article">
<div class="name">the value from the first method</div>
<div class="id">the value from the second method</div>
<div class="description">the value from the third method</div>
</div>
编辑: 以下是我试图实现的扩展示例。两种方法的一个例子。
来自第一个soap方法的print_r(sxml)显示如下结构:
SimpleXMLElement Object
(
[NewDataSet] => SimpleXMLElement Object
(
[HotelFacility] => Array
(
[0] => SimpleXMLElement Object
(
[HotelId] => 1
[HotelCode] => TEST
[FacNo] => 6
[FacName] => test (bank)
[OriginalName] =>
[IsPriced] => No
[MediaID] => 1
[Note] => SimpleXMLElement Object
(
)
[UseinWebFilter] => true
)
[1] => SimpleXMLElement Object
(
[HotelId] => 1
[HotelCode] => TEST2
[FacNo] => 12
[FacName] => test center
[OriginalName] => Test Center
[IsPriced] => No
[MediaID] => 1
[Note] => SimpleXMLElement Object
(
)
[UseinWebFilter] => true
) //and the list continues...
来自第二个soap方法的print_r(sxml2)显示如下结构:
SimpleXMLElement Object
(
[NewDataSet] => SimpleXMLElement Object
(
[HotelPresentation] => Array
(
[0] => SimpleXMLElement Object
(
[RecId] => 5
[HotelId] => 14
[HotelCode] => test hotel
[PresText] => "the description".
[TextType] => HTML
[TextCategory] => GENERAL
[MediaID] => 4
[CrtDate] => 2016-01-06T15:34:00+02:00
[ChgDate] => 2016-01-06T15:34:00+02:00
)
[1] => SimpleXMLElement Object
(
[RecId] => 3
[HotelId] => 4
[HotelCode] => test hotel2
[PresText] => //and the list continues....
如何合并这两个数组并得到结果,让我们说我想制作一个像这样的html结构:
<div class="article">
<div class="name">the value facName from the first method</div>
<div class="id">the value hotelCode from the second method</div>
</div>
<div class="article">
<div class="name">the value facName from the first method</div>
<div class="id">the value hotelCode from the second method</div>
</div>
<div class="article">
<div class="name">the value facName from the first method</div>
<div class="id">the value hotelCode from the second method</div>
</div>
HTML文章将动态显示取决于SOAP方法中有多少结果。
答案 0 :(得分:2)
怎么样:
<style>
.cool-text {
font-family: Lobster;
font-size: 20px;
}
.image-centering {
display: block;
margin-left: auto;
margin-right: auto;
}
.vertical-centering {
margin-top: auto;
margin-bottom: auto;
}
.gray-background {
background-color: lightgray;
margin: 20px 100px 20px 100px;
border-radius: 5px;
}
.white-background {
background-color: white;
margin: 10px 560px 10px 10px;
}
</style>
<div class="gray-background">
<br>
<h1 class="cool-text text-center">J Dilla</h1>
<h2 class="text-center"><i>The one and only</i></h2>
<br>
<div class="span8 offset2">
<div class="img-thumbnail thumbnails">
<img class="image-centering" src="http://media.lessthan3.com/wp-content/uploads/2014/02/j-dilla-lessthan3.jpg" alt="The man himself."</img>
<p class="text-center">Dilla working on something ill, I presume</p>
</div>
</div>
<br>
</div>
</div>
当然,假设HotelFacility和HotelPresentation数组元素可以像这样(通过它们的索引位置)链接在一起。根据你的解释,很难建立两者之间的关系。