标准化多个 SOAP 响应的策略

发布于 2024-08-21 08:38:16 字数 4541 浏览 7 评论 0原文

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

如果我在 SOAP 请求中提供凭据、到达/出发日期,我会收到以下数据,主要包括三件事:房间类型(房间类型和描述)、房价计划(优惠)和房价(用计划/优惠映射房间)。

假设用户指定抵达日期为 2010 年 2 月 20 日,出发日期为 2010 年 2 月 24 日,即抵达/出发,但想要预订 3 个房间:

  • 1x 房间,有 3 名成人 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 标记?

I'm basically trying to merge multiple SOAP responses because the web service only supports one room lookup at a time instead of multiple as far as I know - its the CheckAvailability method and using this WSDL

If I supply my credentials, arrival/departure dates in my SOAP request I get the following data back, which is mainly compromised of 3 things.. Room Types ( type of room and description ), Rate Plans ( deals ) and Room Rates ( maps rooms with plans/deals ).

Let's say the user specifies an arrival date of February 20th and a departure date of February 24th 2010, the arrival/departure but would like to book 3 rooms:

  • 1x Room with 3x adults 2x children
  • 1x Room with 2x adults 1x children
  • 1x Room with 1x adult 0 children

So since we have 3 rooms it has to be 3 requests, because the # of people differ the prices will change.

My main concern is how to merge these such that I can display the room types first in my web page, and within each room type block display the price for each room the user would like, ex:

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

An example of the SOAP response:

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

So basically, in what way should I normalize this markup in order to combine all 3 requests so they can render the HTML markup specified?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

原谅过去的我 2024-08-28 08:38:17

试试这个:

 $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(最好)来进行分割。

Try this:

 $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

Use $dom->loadXML instead of $dom->load if you want to load from a string that contains your XML instead of a disk file.

Once you have everything in one XML listing or DOM, you can either cut apart by iterating (worst), XPath in PHP (better) or XSLT (best).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文