如何从xml响应中获取元素

时间:2022-11-27 17:29:01

I have sent the following xml to the test server,

我已将以下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); 

I get a response that looks like this:

我收到的回复如下:

Response:

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

From this response I am not able to get the element from the car tag. How can I get attributes like 'search id' from car tag with this response?
Thanks.

从这个回复中我无法从汽车标签中获取元素。如何通过此响应从汽车标签获取“搜索ID”等属性?谢谢。

1 个解决方案

#1


0  

From the below result array you can get CAR tag response:

从以下结果数组中,您可以获得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);

#1


0  

From the below result array you can get CAR tag response:

从以下结果数组中,您可以获得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);