1

我基本上是在尝试合并多个 SOAP 响应,因为 据我所知,Web 服务一次只支持一个房间查找,而不是多个 - 它的 CheckAvailability 方法并使用此WSDL

如果我在我的 SOAP 请求中提供我的凭据、到达/离开日期,我会返回以下数据,这些数据主要包含 3 件事.. 房间类型(房间类型和描述)、房价计划(交易)和房价(地图有计划/优惠的房间)。

假设用户指定了 2010 年 2 月 20 日的到达日期和 2010 年 2 月 24 日的离开日期,到达/离开但想预订 3 个房间:

  • 1x 房间 3x 成人 2x 儿童
  • 1x 房间 2x 成人 1x 儿童
  • 1x 房间 1x 成人 0 儿童

因此,由于我们有 3 个房间,因此必须有 3 个请求,因为人数不同,价格会发生变化。

我主要关心的是如何合并这些,以便我可以首先在我的网页中显示房间类型,并在每个房间类型块中显示用户想要的每个房间的价格,例如:

<li>
    <h2>King Suite</h2>
    <h3>Prices</h3>
    <ul class="tabs">
      <li>Room 1<table></table></li>
      <li>Room 2<table></table></li>
      <li>Room 3<table></table></li>
    </ul>
</li>

SOAP 响应的示例:

        <RoomStays>
            <RoomStay>
                <RoomTypes>
                    <RoomType RoomTypeCode="KING" NumberOfUnits="14">
                        <RoomDescription Name="Kings Room">
                            <Text>Content</Text>
                            <Image>http://static.images.com/file.gif</Image>
                        </RoomDescription>
                    </RoomType>
                </RoomTypes>
                <RatePlans>
                    <RatePlan RatePlanCode="SPECIAL" RatePlanName="Special Rate">
                        <RatePlanDescription Name="Published Rate">
                            <Text>Published Rate European Plan</Text>
                        </RatePlanDescription>
                        <Guarantee>
                            <GuaranteeDescription>
                                <Text>1 night room and tax due at the time of reservation</Text>
                            </GuaranteeDescription>
                        </Guarantee>
                        <CancelPenalties>
                            <CancelPenalty>
                                <PenaltyDescription>
                                    <Text>30 day cancellation policy</Text>
                                </PenaltyDescription>
                            </CancelPenalty>
                        </CancelPenalties>
                        <Commission>
                            <Percent>10</Percent>
                        </Commission>
                    </RatePlan>
                </RatePlans>
                <RoomRates>
                    <RoomRate RoomTypeCode="KING" RatePlanCode="SPECIAL">
                        <Rates>
                            <Rate>
                                <Base AmountBeforeTax="1145.00" AmountAfterTax="1145.00" CurrencyCode="USD" />
                                <Total AmountBeforeTax="5725.00" AmountAfterTax="5725.00" CurrencyCode="USD" />
                                <Taxes>
                                    <Tax Amount="0.00" CurrencyCode="USD" />
                                </Taxes>
                                <Tpa_Extensions>
                                    <NightlyRate Date="12/28/2010" Price="1145.00" Tax="0.00" Fee="0.00" PriceWithTaxAndFee="1145.00" />
                                    <NightlyRate Date="12/29/2010" Price="1145.00" Tax="0.00" Fee="0.00" PriceWithTaxAndFee="1145.00" />
                                    <NightlyRate Date="12/30/2010" Price="1145.00" Tax="0.00" Fee="0.00" PriceWithTaxAndFee="1145.00" />
                                    <NightlyRate Date="12/31/2010" Price="1145.00" Tax="0.00" Fee="0.00" PriceWithTaxAndFee="1145.00" />
                                    <NightlyRate Date="1/1/2011" Price="1145.00" Tax="0.00" Fee="0.00" PriceWithTaxAndFee="1145.00" />
                                </Tpa_Extensions>
                            </Rate>
                        </Rates>
                    </RoomRate>
                </RoomRates>
                <BasicPropertyInfo HotelCode="1" HotelName="My Hotel!" />
            </RoomStay>
        </RoomStays>

所以基本上,我应该以什么方式规范化这个标记以便组合所有 3 个请求,以便它们可以呈现指定的 HTML 标记?

4

1 回答 1

1

尝试这个:

 $children = array();
 foreach ($filelist as $file)
 {
   $dom = new DOMDocument();
   $dom->load($file);
   $children[] = $dom->firstChild;
 }
 $output = new DOMDocument();
 $output->appendChild($root = $output->createElement("rootelement"));
 foreach ($children as $child)
 {
   $imported = $output->importNode($child, true);
   $root->appendChild($imported);
 }
 // $output contains a DOMDocument with your aggregate document
 $newxml = $output->saveXML(); // if you want your XML as a string

如果要从包含 XML 的字符串而不是磁盘文件加载,请使用 $dom->loadXML 而不是 $dom->load。

在一个 XML 列表或 DOM 中拥有所有内容后,您可以通过迭代(最差)、PHP 中的 XPath(更好)或 XSLT(最好)来分割。

于 2010-07-25T07:41:50.080 回答