簡體   English   中英

如何從xml響應中獲取元素

[英]How to get the element from the xml response

我已將以下xml發送到測試服務器,

$data=
    '<RQ>
    <Administration>
    <Username>one</Username>
    <Password>one</Password>
    </Administration>
    <Requests>
    <VehicleRQ lang="33" aff="0" reserv_num="" coo="">
    <pickUpLocation>3788</pickUpLocation> 
    <dropOffLocation>3788</dropOffLocation> 
    <PickTime>2015-6-25 12:00</PickTime> 
    <DropTime>2015-6-26 1:00</DropTime> 
    <DrvAge>33</DrvAge> 
    <AddDrvAge /> 
    <PromCode /> 
    <PriceList>5</PriceList> 
    <DrvCountry>gb</DrvCountry> 
    </VehicleRQ>
    </Requests>
    </RQ>';


$ch = curl_init(); 
      curl_setopt ($ch, CURLOPT_URL, 'http://testsdsd.com/aslvaice.php'); 
      curl_setopt ($ch, CURLOPT_POST, 1); 
      curl_setopt ($ch, CURLOPT_POSTFIELDS, $data); 
      curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); 
      $out = curl_exec( $ch); 
      Header ("Content-type: text/xml"); 
      print_r($out); 

我收到如下響應:

響應:

<RS><Administration><Errors/></Administration><Responses><VehicleRS commType="" comm=""><VehicleInfo><Car onRequest="0" id="9349420" group="SUV" subgroup="Standard" class="IFAR" internalClass="SFAR" transmissionId="AUTOMATIC" transmission="Automatic" airco="YES" doors="5" seats="5" airbag="" fuelId="N_A" fuel="N/A" comments="Excess USD 0" image="Toyota-Rav4.jpg" smallSuitcases="4" bigSuitcases="" freeSell="0" searchId="bVDLTsMwEPwXn6PKr8R1byA49NYD4m5sx6xa7GiTVkKIf2cdA0XAcR67sztvbI4O_fM-sF1ve2Ol7Jh3WLFV2mrJOxZg9uWcl0oy1rEJ_PE8PcBLJCy06qWUW85JCVimMo4_pcEOq-QLEpWe6rzzR5diXSfWtAOCp4FBbNSW5Ia02Qh1DY_h8C_PdnThJSKMr58GUe8Aom4SIUVeFwIsULI73V0F_vXILbrcGjBGK_P9xR-ebm4l8PpOXtD5Zc08wfybf4w4U2KLIQ_kdJ8T5NhKfP8A" availChecked="0" excess="0.00" excessCurrency="USD" driverMinimumAge="21" driverMaximumAge="75" gps="0">Toyota Rav4</Car><PriceCust realdeposit="6.5" balancePaymentDate="" commission="0" currency="GBP" localCurrency="USD" drvFee="0.00" addDrvFee="0.00" dropOffFee="0.00" isDropOffFeeLocal="1" isOutOfHoursFeeLocal="1" isYoungDriverFeeLocal="1" outOfHourFee="0.00" discount="0.00" promDiscount="0" mult="0.6619842315356" discountedPrice="47.13" duration="1">47.13</PriceCust><Supplier logo="IsUBeyST.jpg" isMajorSupplier="0" locId="77437" dropLocId="77437" locationId="3788" dropOffLocationId="3788" locName="LAX" isDeposit="1" productType="1" hasOnlinePrices="1" hasXmlBooking="1" supplierId="11" pickUpLatitude="33.9494000" pickUpLongitude="-118.3850000">Sixt</Supplier><Packages><Package id="1" default="1"><Name>Default</Name><Price searchId="bVDLTsMwEPwXn6PKr8R1byA49NYD4m5sx6xa7GiTVkKIf2cdA0XAcR67sztvbI4O_fM-sF1ve2Ol7Jh3WLFV2mrJOxZg9uWcl0oy1rEJ_PE8PcBLJCy06qWUW85JCVimMo4_pcEOq-QLEpWe6rzzR5diXSfWtAOCp4FBbNSW5Ia02Qh1DY_h8C_PdnThJSKMr58GUe8Aom4SIUVeFwIsULI73V0F_vXILbrcGjBGK_P9xR-ebm4l8PpOXtD5Zc08wfybf4w4U2KLIQ_kdJ8T5NhKfP8A" currency="GBP" discountedPrice="47.13 ">47.13 </Price><Items/></Package></Packages><FuelPolicy code=""><Name></Name><Description></Description></FuelPolicy><VehicleAt id=""/></VehicleInfo></VehicleRS></Responses></RS>

從該響應中,我無法從car標簽中獲取元素。 如何通過此響應從car標簽獲取“搜索ID”之類的屬性?
謝謝。

從以下結果數組中,您可以獲得CAR標簽響應:

$simple = '<RS><Administration><Errors/></Administration><Responses><VehicleRS commType="" comm=""><VehicleInfo><Car onRequest="0" id="9349420" group="SUV" subgroup="Standard" class="IFAR" internalClass="SFAR" transmissionId="AUTOMATIC" transmission="Automatic" airco="YES" doors="5" seats="5" airbag="" fuelId="N_A" fuel="N/A" comments="Excess USD 0" image="Toyota-Rav4.jpg" smallSuitcases="4" bigSuitcases="" freeSell="0" searchId="bVDLTsMwEPwXn6PKr8R1byA49NYD4m5sx6xa7GiTVkKIf2cdA0XAcR67sztvbI4O_fM-sF1ve2Ol7Jh3WLFV2mrJOxZg9uWcl0oy1rEJ_PE8PcBLJCy06qWUW85JCVimMo4_pcEOq-QLEpWe6rzzR5diXSfWtAOCp4FBbNSW5Ia02Qh1DY_h8C_PdnThJSKMr58GUe8Aom4SIUVeFwIsULI73V0F_vXILbrcGjBGK_P9xR-ebm4l8PpOXtD5Zc08wfybf4w4U2KLIQ_kdJ8T5NhKfP8A" availChecked="0" excess="0.00" excessCurrency="USD" driverMinimumAge="21" driverMaximumAge="75" gps="0">Toyota Rav4</Car><PriceCust realdeposit="6.5" balancePaymentDate="" commission="0" currency="GBP" localCurrency="USD" drvFee="0.00" addDrvFee="0.00" dropOffFee="0.00" isDropOffFeeLocal="1" isOutOfHoursFeeLocal="1" isYoungDriverFeeLocal="1" outOfHourFee="0.00" discount="0.00" promDiscount="0" mult="0.6619842315356" discountedPrice="47.13" duration="1">47.13</PriceCust><Supplier logo="IsUBeyST.jpg" isMajorSupplier="0" locId="77437" dropLocId="77437" locationId="3788" dropOffLocationId="3788" locName="LAX" isDeposit="1" productType="1" hasOnlinePrices="1" hasXmlBooking="1" supplierId="11" pickUpLatitude="33.9494000" pickUpLongitude="-118.3850000">Sixt</Supplier><Packages><Package id="1" default="1"><Name>Default</Name><Price searchId="bVDLTsMwEPwXn6PKr8R1byA49NYD4m5sx6xa7GiTVkKIf2cdA0XAcR67sztvbI4O_fM-sF1ve2Ol7Jh3WLFV2mrJOxZg9uWcl0oy1rEJ_PE8PcBLJCy06qWUW85JCVimMo4_pcEOq-QLEpWe6rzzR5diXSfWtAOCp4FBbNSW5Ia02Qh1DY_h8C_PdnThJSKMr58GUe8Aom4SIUVeFwIsULI73V0F_vXILbrcGjBGK_P9xR-ebm4l8PpOXtD5Zc08wfybf4w4U2KLIQ_kdJ8T5NhKfP8A" currency="GBP" discountedPrice="47.13 ">47.13 </Price><Items/></Package></Packages><FuelPolicy code=""><Name></Name><Description></Description></FuelPolicy><VehicleAt id=""/></VehicleInfo></VehicleRS></Responses></RS>';
$p = xml_parser_create();
xml_parse_into_struct($p, $simple, $vals);
xml_parser_free($p);
echo '<pre>';
var_dump($vals);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM