Php XML到数组的转换
我在PHP中将XML响应转换为数组时遇到了一些问题 以下是部分给出的SOAP XML响应:Php XML到数组的转换,php,xml,arrays,soap,Php,Xml,Arrays,Soap,我在PHP中将XML响应转换为数组时遇到了一些问题 以下是部分给出的SOAP XML响应: $XMLResponse = ' <Fareportal> <FpSearch_AirLowFaresRS> <CntKey>1777f5a7-7824-46ce-a0f8-33d5e6e96816</CntKey> <Currency CurrencyCode="USD"/> <OriginDestinationOptions&g
$XMLResponse = '
<Fareportal>
<FpSearch_AirLowFaresRS>
<CntKey>1777f5a7-7824-46ce-a0f8-33d5e6e96816</CntKey>
<Currency CurrencyCode="USD"/>
<OriginDestinationOptions>
<OutBoundOptions>
<OutBoundOption segmentid="9W7008V21Feb14">
<FlightSegment FlightNumber="7008" DepartureDateTime="21Feb14T08:20 AM" ArrivalDateTime="21Feb14T09:10 AM" FlightDuration="0.50" FDType="S" StopQuantity="0" RPH="1">
<DepartureAirport LocationCode="MAA"/>
<ArrivalAirport LocationCode="BLR"/>
<Equipment AirEquipType="739"/><FlightCabin CabinType="Y"/><FlightClass ClassType="V"/><MarketingAirline Code="9W"/>
<OperatedByAirline CompanyText="JETKONNECT"/>
<Flight FlightType="O"/>
<Opaque>False</Opaque>
</FlightSegment>
</OutBoundOption>
<OutBoundOption segmentid="9W7030V21Feb2014">
<FlightSegment FlightNumber="7030" DepartureDateTime="21Feb2014T09:30 PM" ArrivalDateTime="21Feb2014T10:25 PM" FlightDuration="00.55" FDType="T" StopQuantity="0" RPH="1">
<DepartureAirport LocationCode="MAA"/>
<ArrivalAirport LocationCode="BLR"/>
<Equipment AirEquipType="739"/><FlightCabin CabinType="Y"/><FlightClass ClassType="V"/><MarketingAirline Code="9W"/>
<OperatedByAirline CompanyText="JETKONNECT"/><Flight FlightType="O"/><Opaque>False</Opaque>
</FlightSegment>
</OutBoundOption>
</OutBoundOptions>
</OriginDestinationOptions>
</FpSearch_AirLowFaresRS>
</Fareportal>
';
我需要得到航班号、起飞日期时间、到达日期时间等详细信息
但我尝试了很多代码,比如simplexmlement、DOMDocument、simplexml\u load\u string所有东西都只返回XML数据,而不是数组
请帮助我了解这种类型的XML响应。有人能给我参考url或建议吗?试试json\u解码-
希望能有所帮助。请向我们展示一些您尝试过的代码。为什么您需要它作为数组而不是对象?您始终可以手动将对象强制转换为数组,即$a=array new simpleXML$xml;hi tularis,对象或数组很好。我尝试过,1.$doc=new DOMDocument$doc->loadXML$soapResponse$结果=$doc->getElementsByTagNamesearchflightavailability33result$结果=$Results->item0->nodeValue;2.simplexml\u load\u字符串$soapResponse、'simplexmlement',LIBXML\u NOCDATA;3.$xml=新的SimpleXMLElement$soapResponse;foreach$xml->children as$second\u gen{echo;print\r$second\u gen;die;}
$xmlObject = simplexml_load_string($xmlString);
$array = json_decode(json_encode($xmlObject), true);