dongling3243 2013-09-24 13:15
浏览 53

将xml转换为php数组

I have following xml data

 <?xml version="1.0" encoding="UTF-8"?>
 <wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="https://www.cashweb.nl/?api" xmlns:ns="https://www.cashweb.nl/?api" targetNamespace="https://www.cashweb.nl/?api">
     <wsdl:types>
         <xsi:schema xmlns:xsi="http://www.w3.org/2001/XMLSchema" targetNamespace="https://www.cashweb.nl/?api" elementFormDefault="qualified">
             <xsi:complexType name="ApiResponse">
                 <xsi:sequence>
                     <xsi:element name="code" type="xs:int"/>
                     <xsi:element name="message" type="xs:string"/>
                 </xsi:sequence>
             </xsi:complexType>
             <xsi:complexType name="Administration">
                 <xsi:sequence>
                     <xsi:element name="admCode" type="xs:string"/>
                     <xsi:element name="admMap" type="xs:string"/>
                 </xsi:sequence>
             </xsi:complexType>
             <xsi:complexType name="Relation">
                 <xsi:sequence>
                     <xsi:element name="relation" type="xs:string"/>
                     <xsi:element name="user" type="xs:string"/>
                 </xsi:sequence>
             </xsi:complexType>
             <xsi:complexType name="Transaction">
                 <xsi:sequence>
                     <xsi:element name="id" type="xsi:string"/>
                     <xsi:element name="status" type="xsi:integer"/>
                     <xsi:element name="creation" type="xsi:string"/>
                     <xsi:element name="lastUpdate" type="xsi:string"/>
                     <xsi:element name="administration" type="ns:Administration"/>
                     <xsi:element name="initiator" type="ns:Relation"/>
                     <xsi:element name="err" type="xsi:string"/>
                 </xsi:sequence>
             </xsi:complexType>
         </xsi:schema>
     </wsdl:types>
     <wsdl:message name="AuthenticateRequest">
         <wsdl:part name="relatie" type="xs:string">
             <wsdl:documentation>The CASHWeb relationnumber used for authentication     </wsdl:documentation>
         </wsdl:part>
         <wsdl:part name="email" type="xs:string">
             <wsdl:documentation>The CASHWeb email  used for authentication     </wsdl:documentation>
         </wsdl:part>
         <wsdl:part name="pass" type="xs:string">
             <wsdl:documentation>The CASHWeb password  used for authentication     </wsdl:documentation>
         </wsdl:part>
         <wsdl:part name="service" type="xs:string">
             <wsdl:documentation>The service is a string that can be used by specific services to identify themselfs to CASH.     </wsdl:documentation>
         </wsdl:part>
     </wsdl:message>
     <wsdl:message name="AuthenticateResponse">
         <wsdl:part name="response" type="tns:ApiResponse">
             <wsdl:documentation>Result code and message indicating the success of the authentication     </wsdl:documentation>
         </wsdl:part>
         <wsdl:part name="token" type="xs:string">
             <wsdl:documentation>In case of authentication success, the returned token is used to identify subsequent API calls     </wsdl:documentation>
         </wsdl:part>
     </wsdl:message>
     <wsdl:message name="ImportRequest">
         <wsdl:part name="token" type="xs:string">
             <wsdl:documentation>Token used to authenticate the API call. Retrieved by calling Authenticate     </wsdl:documentation>
         </wsdl:part>
         <wsdl:part name="importData" type="xs:string">
             <wsdl:documentation>Text content containing valid CASH XML data. After each XML tag a newline character must be present. But after the last XML tag no newline character must be present.     </wsdl:documentation>
         </wsdl:part>
         <wsdl:part name="administration" type="tns:Administration">
             <wsdl:documentation>If the authenticated CASHWeb user represented by the token does not have a default administration code set, this field can be used to indicate to which administration data should be imported.
The administration code must exists as an administration on CASHWeb and it's not allowed to be have any other status except closed. (for example it could be openened manually or it could be synced to CASHWin)

Note: If this element is supplied but the authenticated CASHWeb user has a default administration code set this element will be complete ignored and the default administration code will be used for the import.     </wsdl:documentation>
         </wsdl:part>
     </wsdl:message>
     <wsdl:message name="ImportResponse">
         <wsdl:part name="response" type="tns:ApiResponse">
             <wsdl:documentation>Result code and message indicating the success of the import     </wsdl:documentation>
         </wsdl:part>
         <wsdl:part name="transaction" type="tns:Transaction">
             <wsdl:documentation>The returned transaction object contains the transactions id and other transaction information     </wsdl:documentation>
         </wsdl:part>
     </wsdl:message>
     <wsdl:message name="ExportRequest">
         <wsdl:part name="token" type="xs:string">
             <wsdl:documentation>Token used to authenticate the API call. Retrieved by calling Authenticate     </wsdl:documentation>
         </wsdl:part>
         <wsdl:part name="exportData" type="xs:string">
             <wsdl:documentation>Text content containing valid export command

Example values for the exportData field:
- 0101V-2 (Export all masterdata from relation nr 2)
- 0101P (Export all relations and open invoices per relation)
- 0101T-KVKCASH (Export all relations with the keyword KVKCASH)
- 0450V-BEAMER (Export all masterdata from product BEAMER with actual stock data)
- 2260G-GRP1 (Export all masterdata of all products in de GRP1 productgroup)     </wsdl:documentation>
         </wsdl:part>
         <wsdl:part name="administration" type="tns:Administration">
             <wsdl:documentation>If the authenticated CASHWeb user represented by the token does not have a default administration code set, this field can be used to indicate from which administration data should be exported.
The administration code must exists as an administration on CASHWeb. 

Note: If this element is supplied but the authenticated CASHWeb user has a default admnistration code set this element will be complete ignored and the default administration code will be used for the export.     </wsdl:documentation>
         </wsdl:part>
     </wsdl:message>
     <wsdl:message name="ExportResponse">
         <wsdl:part name="response" type="tns:ApiResponse">
             <wsdl:documentation>Result code and message indicating the success of the export     </wsdl:documentation>
         </wsdl:part>
         <wsdl:part name="exportResult" type="xs:string">
             <wsdl:documentation>The CASH XML data result of the export     </wsdl:documentation>
         </wsdl:part>
     </wsdl:message>
     <wsdl:message name="ListAdministrationsRequest">
         <wsdl:part name="token" type="xs:string">
             <wsdl:documentation>Token used to authenticate the API call. Retrieved by calling Authenticate     </wsdl:documentation>
         </wsdl:part>
     </wsdl:message>
     <wsdl:message name="ListAdministrationsResponse">
         <wsdl:part name="response" type="tns:ApiResponse">
             <wsdl:documentation>Result code and message indicating the success of the administration listing     </wsdl:documentation>
         </wsdl:part>
         <wsdl:part name="administrationList" type="xs:string">
             <wsdl:documentation>An XML document containg a list of all administrations and their status. This also includes all administrations of all cooperating users of the authenticated relation.     </wsdl:documentation>
         </wsdl:part>
     </wsdl:message>
     <wsdl:message name="GetTransactionRequest">
         <wsdl:part name="token" type="xs:string">
             <wsdl:documentation>Token used to authenticate the API call. Retrieved by calling Authenticate     </wsdl:documentation>
         </wsdl:part>
         <wsdl:part name="id" type="xs:string">
             <wsdl:documentation>A 13 character long unique identifier. The id can be found in the transaction element returned by Import or Export.     </wsdl:documentation>
         </wsdl:part>
     </wsdl:message>
     <wsdl:message name="GetTransactionResponse">
         <wsdl:part name="response" type="tns:ApiResponse">
             <wsdl:documentation>Result code and message indicating the success of the administration listing     </wsdl:documentation>
         </wsdl:part>
         <wsdl:part name="transaction" type="tns:Transaction">
             <wsdl:documentation>A transaction object containg information about the transaction that was found matching the id     </wsdl:documentation>
         </wsdl:part>
     </wsdl:message>
     <wsdl:portType name="CASHWebPort">
         <wsdl:documentation>
List of ApiResponse code values:
1   Success                                
2   ErrorLogin                             
3   ErrorFile                              
4   ErrorIssueingToken                     
5   ErrorInvalidToken                      
6   ErrorCorruptedToken                    
7   ErrorUnrecognizedService               
200 ErrorSendPayment                     
300 ErrorLockAndDownload                 
400 ErrorUploadAndUnlock                 
500 ErrorSendingDigipoort                
600 ErrorPuttingFile                     
700 ErrorGettingDirList                  
800 ErrorExporting                       
900 ErrorImporting                       
901 ErrorImportingTransactionFailure          </wsdl:documentation>
         <wsdl:operation name="Authenticate">
             <wsdl:documentation>The Authenticate method identifies a CASHWeb user and returns a token to be used with other methods     </wsdl:documentation>
             <wsdl:input message="tns:AuthenticateRequest"/>
             <wsdl:output message="tns:AuthenticateResponse"/>
         </wsdl:operation>
         <wsdl:operation name="Import">
             <wsdl:documentation>The Import method imports CASH XML data into the administration which the authenticated user is linked with     </wsdl:documentation>
             <wsdl:input message="tns:ImportRequest"/>
             <wsdl:output message="tns:ImportResponse"/>
         </wsdl:operation>
         <wsdl:operation name="Export">
             <wsdl:documentation>The Export method exports CASH XML data from the administration     </wsdl:documentation>
             <wsdl:input message="tns:ExportRequest"/>
             <wsdl:output message="tns:ExportResponse"/>
         </wsdl:operation>
         <wsdl:operation name="ListAdministrations">
             <wsdl:documentation>The ListAdministrations method will create a XML document that lists all administrations the authenticated user has access to.     </wsdl:documentation>
             <wsdl:input message="tns:ListAdministrationsRequest"/>
             <wsdl:output message="tns:ListAdministrationsResponse"/>
         </wsdl:operation>
         <wsdl:operation name="GetTransaction">
             <wsdl:input message="tns:GetTransactionRequest"/>
             <wsdl:output message="tns:GetTransactionResponse"/>
         </wsdl:operation>
     </wsdl:portType>
     <wsdl:binding name="CASHWebBinding" type="tns:CASHWebPort">
         <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
         <wsdl:operation name="Authenticate">
             <soap:operation soapAction="urn:#Authenticate"/>
             <wsdl:input>
                 <soap:body use="literal"/>
             </wsdl:input>
             <wsdl:output>
                 <soap:body use="literal" namespace="http://schemas.xmlsoap.org/soap/envelope/"/>
             </wsdl:output>
         </wsdl:operation>
         <wsdl:operation name="Import">
             <soap:operation soapAction="urn:#Import"/>
             <wsdl:input>
                 <soap:body use="literal"/>
             </wsdl:input>
             <wsdl:output>
                 <soap:body use="literal" namespace="http://schemas.xmlsoap.org/soap/envelope/"/>
             </wsdl:output>
         </wsdl:operation>
         <wsdl:operation name="Export">
             <soap:operation soapAction="urn:#Export"/>
             <wsdl:input>
                 <soap:body use="literal"/>
             </wsdl:input>
             <wsdl:output>
                 <soap:body use="literal" namespace="http://schemas.xmlsoap.org/soap/envelope/"/>
             </wsdl:output>
         </wsdl:operation>
         <wsdl:operation name="ListAdministrations">
             <soap:operation soapAction="urn:#ListAdministrations"/>
             <wsdl:input>
                 <soap:body use="literal"/>
             </wsdl:input>
             <wsdl:output>
                 <soap:body use="literal" namespace="http://schemas.xmlsoap.org/soap/envelope/"/>
             </wsdl:output>
         </wsdl:operation>
         <wsdl:operation name="GetTransaction">
             <soap:operation soapAction="urn:#GetTransaction"/>
             <wsdl:input>
                 <soap:body use="literal"/>
             </wsdl:input>
             <wsdl:output>
                 <soap:body use="literal" namespace="http://schemas.xmlsoap.org/soap/envelope/"/>
             </wsdl:output>
         </wsdl:operation>
     </wsdl:binding>
     <wsdl:service name="CASHWebService">
         <wsdl:port name="CASHWebPort" binding="tns:CASHWebBinding">
             <soap:address location="https://www.cashweb.nl/?api"/>
         </wsdl:port>
     </wsdl:service>
 </wsdl:definitions>

And I am using following php function for converting xml to php arrat

 $response_xml_data = file_get_contents($map_url);
       $a = json_decode(json_encode((array) simplexml_load_string($response_xml_data)),1);
print_r($a);

And I got following result

Array
(
    [@attributes] => Array
        (
            [targetNamespace] => https://www.cashweb.nl/?api
        )

)

please tell me what is wrong or any mistake with the above code, I am not getting proper xml to php array result.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度