我查找了有关这方面的所有资源,我通常使用json_encode方法将xml转换为json或数组,但它在这种特定情况下不起作用,而且它确实令人困惑,var_dump总是返回空结果(实际上这是:string(2)“{}”)!
代码是:
$xml = simplexml_load_string($xml);
if ($xml === FALSE) {
throw new Exception('Failed to load XML string.');
}
$xml_array = json_encode($xml);
var_dump($xml_array);
,xml是:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<GetTicketTypeListResult xmlns="http://vista.co.nz/services/WSVistaWebClient.DataTypes/1/">
<Result>OK</Result>
<DatasetXML>
<NewDataSet>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="NewDataSet">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Table">
<xs:complexType>
<xs:sequence>
<xs:element name="IsPaid" type="xs:int" minOccurs="0" />
<xs:element name="AvailableOnSalesChannel" type="xs:int" minOccurs="0" />
<xs:element name="IsDisplayedStandard" type="xs:int" minOccurs="0" />
<xs:element name="IsLoyaltyOnly" type="xs:int" minOccurs="0" />
<xs:element name="OrderPricesBy" type="xs:int" minOccurs="0" />
<xs:element name="TicketHasBarcode" type="xs:string" minOccurs="0" />
<xs:element name="Cinema_strID" type="xs:string" minOccurs="0" />
<xs:element name="Session_strID" type="xs:string" minOccurs="0" />
<xs:element name="AreaCat_strCode" type="xs:string" minOccurs="0" />
<xs:element name="AreaCat_strSeatAllocationOn" type="xs:string" minOccurs="0" />
<xs:element name="Cinema_strID1" type="xs:string" minOccurs="0" />
<xs:element name="Price_strTicket_Type_Code" type="xs:string" minOccurs="0" />
<xs:element name="Price_strTicket_Type_Description" type="xs:string" minOccurs="0" />
<xs:element name="Price_strGroup_Code" type="xs:string" minOccurs="0" />
<xs:element name="Price_intTicket_Price" type="xs:int" minOccurs="0" />
<xs:element name="Price_strChild_Ticket" type="xs:string" minOccurs="0" />
<xs:element name="AreaCat_strCode1" type="xs:string" minOccurs="0" />
<xs:element name="AreaCat_intSeq" type="xs:int" minOccurs="0" />
<xs:element name="Price_strTicket_Type_Description_2" type="xs:string" minOccurs="0" />
<xs:element name="Price_strPackage" type="xs:string" minOccurs="0" />
<xs:element name="TType_strAvailLoyaltyOnly" type="xs:string" minOccurs="0" />
<xs:element name="TType_strHOCode" type="xs:string" minOccurs="0" />
<xs:element name="Price_strRedemption" type="xs:string" minOccurs="0" />
<xs:element name="Price_strComp" type="xs:string" minOccurs="0" />
<xs:element name="TType_strSalesChannels" type="xs:string" minOccurs="0" />
<xs:element name="Price_strATMAvailable" type="xs:string" minOccurs="0" />
<xs:element name="TType_strShowOnPOS" type="xs:string" minOccurs="0" />
<xs:element name="Price_intSurcharge" type="xs:int" minOccurs="0" />
<xs:element name="TType_intBarcodeMaxRepeats" type="xs:int" minOccurs="0" />
<xs:element name="TType_strMaxRepeatsCycle" type="xs:string" minOccurs="0" />
<xs:element name="TType_strLongDescription" type="xs:string" minOccurs="0" />
<xs:element name="TType_strLongDescriptionAlt" type="xs:string" minOccurs="0" />
<xs:element name="TType_strMemberCard" type="xs:string" minOccurs="0" />
<xs:element name="TType_strAvailRecognitionOnly" type="xs:string" minOccurs="0" />
<xs:element name="HOPK" type="xs:string" minOccurs="0" />
<xs:element name="AreaCat_strDesc" type="xs:string" minOccurs="0" />
<xs:element name="AreaCat_strDescAlt" type="xs:string" minOccurs="0" />
<xs:element name="MMC_strName" type="xs:string" minOccurs="0" />
<xs:element name="Price_strIsTicketPackage" type="xs:string" minOccurs="0" />
<xs:element name="LoyaltyRewardTicket" type="xs:string" minOccurs="0" />
<xs:element name="LoyaltyTicketName" type="xs:string" minOccurs="0" />
<xs:element name="LoyaltyTicketDescription" type="xs:string" minOccurs="0" />
<xs:element name="LoyaltyTicketMessageText" type="xs:string" minOccurs="0" />
<xs:element name="OrderTicketsBy" type="xs:string" minOccurs="0" />
<xs:element name="TicketCategory" type="xs:string" minOccurs="0" />
<xs:element name="Price_strLoyaltyRecognitionID" type="xs:string" minOccurs="0" />
<xs:element name="Price_intLoyaltyDisplayPrice" type="xs:string" minOccurs="0" />
<xs:element name="Price_intLoyaltyPriceCents" type="xs:string" minOccurs="0" />
<xs:element name="Price_intLoyaltyPointsCost" type="xs:string" minOccurs="0" />
<xs:element name="Price_intLoyaltyQtyAvailable" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<Table>
<IsPaid>1</IsPaid>
<AvailableOnSalesChannel>1</AvailableOnSalesChannel>
<IsDisplayedStandard>1</IsDisplayedStandard>
<IsLoyaltyOnly>0</IsLoyaltyOnly>
<OrderPricesBy>1</OrderPricesBy>
<TicketHasBarcode>N</TicketHasBarcode>
<Cinema_strID>0</Cinema_strID>
<Session_strID>79731</Session_strID>
<AreaCat_strCode>0000000001</AreaCat_strCode>
<AreaCat_strSeatAllocationOn>Y</AreaCat_strSeatAllocationOn>
<Cinema_strID1>0</Cinema_strID1>
<Price_strTicket_Type_Code>0001</Price_strTicket_Type_Code>
<Price_strTicket_Type_Description>Standard</Price_strTicket_Type_Description>
<Price_strGroup_Code>7010</Price_strGroup_Code>
<Price_intTicket_Price>1400000</Price_intTicket_Price>
<Price_strChild_Ticket>N</Price_strChild_Ticket>
<AreaCat_strCode1>0000000001</AreaCat_strCode1>
<AreaCat_intSeq>1</AreaCat_intSeq>
<Price_strTicket_Type_Description_2 />
<Price_strPackage>N</Price_strPackage>
<TType_strAvailLoyaltyOnly>N</TType_strAvailLoyaltyOnly>
<TType_strHOCode>ST00000001</TType_strHOCode>
<Price_strRedemption>N</Price_strRedemption>
<Price_strComp>N</Price_strComp>
<TType_strSalesChannels>;CALL;CELL;GSALE;IVR;KIOSK;PDA;POS;POSBK;RSP;WWW;</TType_strSalesChannels>
<Price_strATMAvailable>Y</Price_strATMAvailable>
<TType_strShowOnPOS>Y</TType_strShowOnPOS>
<Price_intSurcharge>0</Price_intSurcharge>
<TType_intBarcodeMaxRepeats>1</TType_intBarcodeMaxRepeats>
<TType_strMaxRepeatsCycle>O</TType_strMaxRepeatsCycle>
<TType_strLongDescription />
<TType_strLongDescriptionAlt />
<TType_strMemberCard>N</TType_strMemberCard>
<TType_strAvailRecognitionOnly />
<HOPK />
<AreaCat_strDesc>STANDARD</AreaCat_strDesc>
<AreaCat_strDescAlt />
<MMC_strName />
<Price_strIsTicketPackage>N</Price_strIsTicketPackage>
<OrderTicketsBy>1</OrderTicketsBy>
<TicketCategory>STANDARD</TicketCategory>
</Table>
<Table>
<IsPaid>0</IsPaid>
<AvailableOnSalesChannel>0</AvailableOnSalesChannel>
<IsDisplayedStandard>0</IsDisplayedStandard>
<IsLoyaltyOnly>0</IsLoyaltyOnly>
<OrderPricesBy>6</OrderPricesBy>
<TicketHasBarcode>N</TicketHasBarcode>
<Cinema_strID>0</Cinema_strID>
<Session_strID>79731</Session_strID>
<AreaCat_strCode>0000000001</AreaCat_strCode>
<AreaCat_strSeatAllocationOn>Y</AreaCat_strSeatAllocationOn>
<Cinema_strID1>0</Cinema_strID1>
<Price_strTicket_Type_Code>0002</Price_strTicket_Type_Code>
<Price_strTicket_Type_Description>Complimentary</Price_strTicket_Type_Description>
<Price_strGroup_Code>7010</Price_strGroup_Code>
<Price_intTicket_Price>0</Price_intTicket_Price>
<Price_strChild_Ticket>N</Price_strChild_Ticket>
<AreaCat_strCode1>0000000001</AreaCat_strCode1>
<AreaCat_intSeq>1</AreaCat_intSeq>
<Price_strTicket_Type_Description_2 />
<Price_strPackage>N</Price_strPackage>
<TType_strAvailLoyaltyOnly>N</TType_strAvailLoyaltyOnly>
<TType_strHOCode />
<Price_strRedemption>N</Price_strRedemption>
<Price_strComp>Y</Price_strComp>
<TType_strSalesChannels>;POS;POSBK;</TType_strSalesChannels>
<Price_strATMAvailable>Y</Price_strATMAvailable>
<TType_strShowOnPOS>Y</TType_strShowOnPOS>
<Price_intSurcharge>0</Price_intSurcharge>
<TType_intBarcodeMaxRepeats>1</TType_intBarcodeMaxRepeats>
<TType_strMaxRepeatsCycle>O</TType_strMaxRepeatsCycle>
<TType_strLongDescription />
<TType_strLongDescriptionAlt />
<TType_strMemberCard>N</TType_strMemberCard>
<TType_strAvailRecognitionOnly />
<HOPK />
<AreaCat_strDesc>STANDARD</AreaCat_strDesc>
<AreaCat_strDescAlt />
<MMC_strName />
<Price_strIsTicketPackage>N</Price_strIsTicketPackage>
<OrderTicketsBy>3</OrderTicketsBy>
<TicketCategory>VOUCHER</TicketCategory>
</Table>
</NewDataSet>
</DatasetXML>
</GetTicketTypeListResult>
</soap:Body>
</soap:Envelope>