douwei7976 2018-03-05 08:35
浏览 54
已采纳

无法转换OTA API xml响应?

I'm trying to parse OTA service's XML response in PHP. I have tried below code but no luck.

$doc = new DOMDocument();

$doc->loadXML($response);

$XMLresults = $doc->getElementsByTagName("OTA_VehAvailRateRS");

I want to get different tags value from xml response. Can someone help me out from this? Thanks. For example i want to parse following xml response:

<?xml version="1.0"?> 
<OTA_VehAvailRateRS xmlns="http://www.opentravel.org/OTA/2003/05" TimeStamp="2018-02-28T01:12:27" Target="Test" Version="4.500" SequenceNmbr="1"> 
    <Success/> 
    <VehAvailRSCore> 
    <VehRentalCore PickUpDateTime="2018-03-13T08:00:00" ReturnDateTime="2018-03-30T08:00:00"> 
    <PickUpLocation LocationCode="TEST"/> 
    <ReturnLocation LocationCode="TEST"/> 
    </VehRentalCore> 
    <VehVendorAvails> 
    <VehVendorAvail> 
    <VehAvails> <VehAvail> 
    <VehAvailCore Status="Available"> 
    <Vehicle Code="TEST15" VendorCarType="TEST15" Description="TEST"/> 
    <RentalRate> 
    <RateDistance Unlimited="True" DistUnitName="Mile" VehiclePeriodUnitName="RentalPeriod"/> 
    <VehicleCharges> 
    <VehicleCharge Description="TEST" Amount="1299.35" CurrencyCode="" GuaranteedInd="True" Purpose="1"> <Calculation UnitCharge="33.32" UnitName="Hour"/> 
    <Calculation UnitCharge="1560.00" UnitName="Month"/> 
    <Calculation UnitCharge="499.75" UnitName="Week"/> 
    <Calculation UnitCharge="99.95" UnitName="Day"/> 
    <TaxAmounts> </TaxAmounts> 
    </VehicleCharge> 
    </VehicleCharges> 
    </RentalRate> 
    <Fees> </Fees> 
    <TotalCharge CurrencyCode="" RateTotalAmount="1299.35" EstimatedTotalAmount="1299.35"/> 
    <PricedEquips> </PricedEquips> </VehAvailCore> <VehAvailInfo> <PricedCoverages> </PricedCoverages> </VehAvailInfo> </VehAvail> </VehAvails> </VehVendorAvail> </VehVendorAvails> </VehAvailRSCore> </OTA_VehAvailRateRS>
  • 写回答

1条回答 默认 最新

  • duanhai1455 2018-03-07 09:31
    关注

    I have found solution. I have used simplexml_load_string() function for parse response. For ex:

    $xml = simplexml_load_string($finalresponse);
    var_dump($xml); //getting parsed response here
    

    For getting value of different xml nodes i have used below code:

    $nodevalue = $xml->VehAvailRSCore->VehRentalCore->attributes()->PickUpDateTime; //this code gives me "2018-03-13T08:00:00" as result
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 ubuntu系统下挂载磁盘上执行./提示权限不够
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误