我正在尝试使用CURL调用SOAP API请求,这是我的代码:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body xmlns:s="http://www.w3.org/2003/05/soap-envelope">
<tns:createReservationResp xmlns:tns="http://xxxxx.com">
<tns:success>true</tns:success>
<tns:message>Test Garage order orderNumber168. created 2015-11-19 00:30:57.905</tns:message>
<tns:orderTime>2015-11-19 00:30:57.905</tns:orderTime>
<tns:reservations>
<tns:garageID>47</tns:garageID>
<tns:barCode>barCode168</tns:barCode>
<tns:licensePlate>licensePlate168</tns:licensePlate>
<tns:orderNumber>orderNumber168</tns:orderNumber>
<tns:used>false</tns:used>
<tns:cancelled>false</tns:cancelled>
<tns:startTime>2015-11-20 22:53:45.547</tns:startTime>
<tns:endTime>2015-11-21 22:53:45.547</tns:endTime>
<tns:cancelledTime/>
<tns:checkInTime/>
<tns:checkOutTime/>
<tns:grossPrice>152.6</tns:grossPrice>
<tns:commFee>162.6</tns:commFee>
<tns:customerName>customerName168</tns:customerName>
<tns:customerEmail>customerEmail168</tns:customerEmail>
<tns:customerPhone>customerPhone168</tns:customerPhone>
<tns:vehicleMake>vehicleMake168</tns:vehicleMake>
<tns:vehicleModel>vehicleModel68</tns:vehicleModel>
<tns:vehicleColor>vehicleColor168</tns:vehicleColor>
<tns:reentryAllowed>true</tns:reentryAllowed>
</tns:reservations>
</tns:createReservationResp>
</soapenv:Body>
</soapenv:Envelope>
现在我不明白如何从xml响应中读取值。我在这里添加我的回复数据,这样你就可以得到正确的想法:
<tns:success>true</tns:success>
<tns:message>Test Garage order orderNumber168. created 2015-11-19 00:30:57.905</tns:message>
<tns:orderTime>2015-11-19 00:30:57.905</tns:orderTime>
<tns:garageID>47</tns:garageID>
<tns:barCode>barCode168</tns:barCode>
我想从响应中读取这个值:
view.scene.transform
任何想法?
感谢。
答案 0 :(得分:1)
一般来说,在处理SOAP而不是curl时应该使用SoapClient。它提供了更清晰的界面。在你的情况下,需要使用SimpleXML函数,SitePoint上有一个很好的教程。
$soapenv = $xml->children("http://schemas.xmlsoap.org/soap/envelope/");
$tns = $soapenv->Body->children("http://xxxxx.com");
echo "success: " . $tns->createReservationResp->success . "\n";
echo "message: " . $tns->createReservationResp->message . "\n";
echo "orderTime: " . $tns->createReservationResp->orderTime . "\n";
echo "garageID: " . $tns->createReservationResp->reservations->garageID . "\n";
echo "barCode: " . $tns->createReservationResp->reservations->barCode . "\n";