doubailian4459 2011-07-07 13:37
浏览 28
已采纳

如何使用php在curl xml响应中显示值?

Can we change this xml response into array. Please help me.

  <?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 <soapenv:Body>
      <ns1:OTA_HotelAvailRQResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://components.hotelsv3">
           <OTA_HotelAvailRQReturn xsi:type="xsd:string"><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
                <OTA_HotelAvailRS Version=&quot;1.0&quot;>
                     <Success Id=&quot;141334&quot;/>

                     <Properties>

                          <Property HotelCityCode=&quot;ELS&quot; HotelCode=&quot;26824&quot; HotelName=&quot;Premier Hotel Regent - Demo&quot;>
                                    <RelativePosition Direction=&quot;&quot; Distance=&quot;0&quot; DistanceUnitName=&quot;&quot;/>

                               <EssentialInfo>

                               </EssentialInfo>
                               <RoomStays>

                                    <RoomStay>
                                         <RatePlans>
                                              <RatePlan RatePlanCode=&quot;71316&quot;/>

                                         </RatePlans>
                                         <RoomRates>
                                              <RoomRate>
                                                   <Rates>
                                                        <Rate EffectiveDate=&quot;2011-10-14&quot; ExpireDate=&quot;2011-10-15&quot;>

                                                             <Base Amount=&quot;114.00&quot; CurrencyCode=&quot;EUR&quot;/>
                                                             <RateDescription Adults=&quot;1&quot; Availability=&quot;A&quot; Children=&quot;0&quot; RoomNum=&quot;1&quot;>

                                                                  Standard 
                                                             </RateDescription>
                                                        </Rate>
                                                   </Rates>
                                              </RoomRate>
                                         </RoomRates>

                                         <Meals Description=&quot;Breakfast Buffet&quot; MealType=&quot;Breakfast&quot;/>


                                           </RoomStay>

                               </RoomStays>
                               <Promotions/>

                               <AdditionalInfo>
                                    <HotelStarDetail rating=&quot;3&quot;/>


                                    <HotelImages>

                                         <HotelImage Type=&quot;&quot; URL=&quot;http://image1.urlforimages.com/1204258/Premier-Hotel-Regent_guest.jpg&quot;/>

                                                </HotelImages>

                                    <HotelDescription>
                                         <LongDescription>  guest rooms  175 guestrooms</LongDescription>

                                    </HotelDescription>
                               </AdditionalInfo>

                          </Property>

                          <Property HotelCityCode=&quot;ELS&quot; HotelCode=&quot;26823&quot; HotelName=&quot;Mpongo Private Game Reserve - Demo&quot;>

                                    <RelativePosition Direction=&quot;&quot; Distance=&quot;0&quot; DistanceUnitName=&quot;&quot;/>
                               <EssentialInfo>

                               </EssentialInfo>
                               <RoomStays>


                                    <RoomStay>
                                         <RatePlans>
                                              <RatePlan RatePlanCode=&quot;71314&quot;/>
                                         </RatePlans>
                                         <RoomRates>

                                              <RoomRate>
                                                   <Rates>
                                                        <Rate EffectiveDate=&quot;2011-10-14&quot; ExpireDate=&quot;2011-10-15&quot;>
                                                             <Base Amount=&quot;117.00&quot; CurrencyCode=&quot;EUR&quot;/>

                                                             <RateDescription Adults=&quot;1&quot; Availability=&quot;A&quot; Children=&quot;0&quot; RoomNum=&quot;1&quot;>
                                                                  Standard 
                                                             </RateDescription>

                                                        </Rate>
                                                   </Rates>
                                              </RoomRate>
                                         </RoomRates>

                                         <Meals Description=&quot;Half board&quot; MealType=&quot;HalfBoard&quot;/>


                                           </RoomStay>

                                    <RoomStay>
                                         <RatePlans>
                                              <RatePlan RatePlanCode=&quot;71315&quot;/>
                                         </RatePlans>

                                         <RoomRates>
                                              <RoomRate>
                                                   <Rates>
                                                        <Rate EffectiveDate=&quot;2011-10-14&quot; ExpireDate=&quot;2011-10-15&quot;>
                                                             <Base Amount=&quot;174.00&quot; CurrencyCode=&quot;EUR&quot;/>

                                                             <RateDescription Adults=&quot;1&quot; Availability=&quot;A&quot; Children=&quot;0&quot; RoomNum=&quot;1&quot;>
                                                                  River Lodge 
                                                             </RateDescription>

                                                        </Rate>
                                                   </Rates>
                                              </RoomRate>
                                         </RoomRates>

                                         <Meals Description=&quot;Half board&quot; MealType=&quot;HalfBoard&quot;/>


                                           </RoomStay>

                               </RoomStays>
                               <Promotions/>

                               <AdditionalInfo>
                                    <HotelStarDetail rating=&quot;4&quot;/>


                                    <HotelImages>

                                         <HotelImage Type=&quot;&quot; URL=&quot;http://image1.urlforimages.com/1204253/Mpongo-Private_guest.jpg&quot;/>

                                                </HotelImages>

                                    <HotelDescription>
                                         <LongDescription>  Accommodation: 18 guestrooms</LongDescription>

                                    </HotelDescription>
                               </AdditionalInfo>

                          </Property>
                     </Properties>
           </OTA_HotelAvailRS></OTA_HotelAvailRQReturn>
      </ns1:OTA_HotelAvailRQResponse>

 </soapenv:Body>

  • 写回答

1条回答 默认 最新

  • duanjian3920 2011-07-08 01:35
    关注

    Have a look at http://www.php.net/manual/en/class.domdocument.php

    <?php
    
    $doc = new DOMDocument();
    $doc->loadXML($xml);
    $nodes = $doc->getElementsByTagName('*');
    $values = array();
    
    foreach($nodes as $node) {
      $values[] = $node->nodeValue;
    }
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 python天天向上类似问题,但没有清零
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 C#调用python代码(python带有库)
  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)