PHP:在SOAP响应读取XML属性

问题描述:

我试图使用内置的SOAP客户端带着几分复杂的WSDL结构PHP5,这里定义的:http://cmis.alfresco.com/cmis/NavigationService?wsdlPHP:在SOAP响应读取XML属性

我定义的所有类型的类和类型映射,我可以在__doRequest函数中看到有效的SOAP XML请求和响应。但是,__doRequest返回并且PHP将数据转换为对象和数组后,我缺少作为XML属性返回的所有信息,而不是元素。

这里是SOAP请求外出到服务器:

<?xml version="1.0" encoding="UTF-8"?> 
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" 
xmlns:ns1="http://docs.oasis-open.org/ns/cmis/messaging/200908/" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:ns2="http://docs.oasis-open.org/ns/cmis/ws/200908/" 
xmlns:ns3="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> 

<env:Header> 
<ns3:Security env:mustUnderstand="true"> 
<Timestamp xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> 
<Created>2012-08-02T17:16:11Z</Created> 
<Expires>2012-08-02T18:16:11Z</Expires> 
</Timestamp> 
<ns3:UsernameToken><ns3:Username>***</ns3:Username> 
<ns3:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">***</ns3:Password></ns3:UsernameToken> 
</ns3:Security> 
</env:Header> 

<env:Body> 
<ns1:getChildren xsi:type="ns2:getChildren"> 
<ns1:repositoryId>a8b08c6a-96e0-4783-a062-bc0ae106a2f2</ns1:repositoryId> 
<ns1:folderId>workspace://SpacesStore/b461d5ac-5df9-48ec-84ed-03257c411227</ns1:folderId> 
<ns1:filter>*</ns1:filter><ns1:orderBy/><ns1:includeAllowableActions/><ns1:includeRelationships/> 
<ns1:renditionFilter/><ns1:includePathSegment/><ns1:maxItems/><ns1:skipCount/><ns1:extension/> 
</ns1:getChildren> 
</env:Body></env:Envelope> 

这里是SOAP响应回来,短路用于重复条目:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
<soap:Header> 
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> 
<wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="Timestamp-1464665770"> 
<wsu:Created xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">2012-08-01T15:16:19.407Z</wsu:Created> 
<wsu:Expires xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">2012-08-01T15:21:19.407Z</wsu:Expires> 
</wsu:Timestamp> 
</wsse:Security> 
</soap:Header> 

<soap:Body> 
    <getChildrenResponse xmlns="http://docs.oasis-open.org/ns/cmis/messaging/200908/" 
    xmlns:ns2="http://docs.oasis-open.org/ns/cmis/core/200908/" 
    xmlns:ns3="http://www.alfresco.org"> 
    <objects> 
    <objects> 
     <object> 
     <ns2:properties> 
      <ns2:propertyId propertyDefinitionId="cmis:objectTypeId"> 
      <ns2:value>cmis:folder</ns2:value> 
      </ns2:propertyId> 
      <ns2:propertyString propertyDefinitionId="cmis:path"> 
      <ns2:value>/Data Dictionary</ns2:value> 
      </ns2:propertyString> 
      <ns2:propertyString propertyDefinitionId="cmis:name"> 
      <ns2:value>Data Dictionary</ns2:value> 
      </ns2:propertyString> 
      <ns2:propertyDateTime propertyDefinitionId="cmis:creationDate"> 
      <ns2:value>2012-06-24T11:08:45.282+02:00</ns2:value> 
      </ns2:propertyDateTime> 
      <ns2:propertyString propertyDefinitionId="cmis:lastModifiedBy"> 
      <ns2:value>System</ns2:value> 
      </ns2:propertyString> 
      <ns2:propertyString propertyDefinitionId="cmis:createdBy"> 
      <ns2:value>System</ns2:value> 
      </ns2:propertyString> 
      <ns2:propertyId propertyDefinitionId="cmis:objectId"> 
      <ns2:value>workspace://SpacesStore/14f3706f-a999-4e56-a19a-49c34db0fbe8</ns2:value> 
      </ns2:propertyId> 
      <ns2:propertyId propertyDefinitionId="cmis:baseTypeId"> 
      <ns2:value>cmis:folder</ns2:value> 
      </ns2:propertyId> 
      <ns2:propertyDateTime propertyDefinitionId="cmis:lastModificationDate"> 
      <ns2:value>2012-06-24T11:08:53.940+02:00</ns2:value> 
      </ns2:propertyDateTime> 
      <ns2:propertyId propertyDefinitionId="cmis:parentId"> 
      <ns2:value>workspace://SpacesStore/b461d5ac-5df9-48ec-84ed-03257c411227</ns2:value> 
      </ns2:propertyId> 
      <ns3:aspects> 
      <ns3:appliedAspects>P:sys:localized</ns3:appliedAspects> 
      <ns3:appliedAspects>P:cm:titled</ns3:appliedAspects> 
      <ns3:appliedAspects>P:app:uifacets</ns3:appliedAspects> 
      <ns3:properties> 
       <ns2:propertyString propertyDefinitionId="cm:title"> 
       <ns2:value>Data Dictionary</ns2:value> 
       </ns2:propertyString> 
       <ns2:propertyString propertyDefinitionId="cm:description"> 
       <ns2:value>User managed definitions</ns2:value> 
       </ns2:propertyString> 
       <ns2:propertyString propertyDefinitionId="app:icon"> 
       <ns2:value>space-icon-default</ns2:value> 
       </ns2:propertyString> 
      </ns3:properties> 
      </ns3:aspects> 
     </ns2:properties> 
     </object> 
    </objects> 

    ... 

    <hasMoreItems>false</hasMoreItems> 
    <numItems>5</numItems> 
    </objects> 
    </getChildrenResponse> 
</soap:Body> 

</soap:Envelope> 

生成的对象的一个​​的var_dump给出以下输出。 propertyDefinitionId的所有属性数据完全丢失:

array(5) { 
    [0]=> 
    object(cmisObjectInFolderType)#137 (3) { 
    ["object"]=> 
    object(cmisObjectType)#136 (9) { 
     ["properties"]=> 
     array(8) { 
     [0]=> 
     object(cmisPropertyString)#132 (5) { 
      ["value"]=> 
      array(1) { 
      [0]=> 
      string(16) "/Data Dictionary" 
      } 
      ["propertyDefinitionId"]=> 
      object(stdClass)#133 (0) { 
      } 
      ["localName"]=> 
      NULL 
      ["displayName"]=> 
      NULL 
      ["queryName"]=> 
      NULL 
     } 
     [1]=> 
     object(cmisPropertyString)#140 (5) { 
      ["value"]=> 
      array(1) { 
      [0]=> 
      string(15) "Data Dictionary" 
      } 
      ["propertyDefinitionId"]=> 
      object(stdClass)#133 (0) { 
      } 
      ["localName"]=> 
      NULL 
      ["displayName"]=> 
      NULL 
      ["queryName"]=> 
      NULL 
     } 
     [2]=> 
     object(cmisPropertyString)#141 (5) { 
      ["value"]=> 
      array(1) { 
      [0]=> 
      string(6) "System" 
      } 
      ["propertyDefinitionId"]=> 
      object(stdClass)#133 (0) { 
      } 
      ["localName"]=> 
      NULL 
      ["displayName"]=> 
      NULL 
      ["queryName"]=> 
      NULL 
     } 
     [3]=> 
     object(cmisPropertyString)#142 (5) { 
      ["value"]=> 
      array(1) { 
      [0]=> 
      string(6) "System" 
      } 
      ["propertyDefinitionId"]=> 
      object(stdClass)#133 (0) { 
      } 
      ["localName"]=> 
      NULL 
      ["displayName"]=> 
      NULL 
      ["queryName"]=> 
      NULL 
     } 
     [4]=> 
     object(cmisPropertyId)#143 (5) { 
      ["value"]=> 
      array(1) { 
      [0]=> 
      string(11) "cmis:folder" 
      } 
      ["propertyDefinitionId"]=> 
      object(stdClass)#133 (0) { 
      } 
      ["localName"]=> 
      NULL 
      ["displayName"]=> 
      NULL 
      ["queryName"]=> 
      NULL 
     } 
     [5]=> 
     object(cmisPropertyId)#144 (5) { 
      ["value"]=> 
      array(1) { 
      [0]=> 
      string(60) "workspace://SpacesStore/14f3706f-a999-4e56-a19a-49c34db0fbe8" 
      } 
      ["propertyDefinitionId"]=> 
      object(stdClass)#133 (0) { 
      } 
      ["localName"]=> 
      NULL 
      ["displayName"]=> 
      NULL 
      ["queryName"]=> 
      NULL 
     } 
     [6]=> 
     object(cmisPropertyId)#145 (5) { 
      ["value"]=> 
      array(1) { 
      [0]=> 
      string(11) "cmis:folder" 
      } 
      ["propertyDefinitionId"]=> 
      object(stdClass)#133 (0) { 
      } 
      ["localName"]=> 
      NULL 
      ["displayName"]=> 
      NULL 
      ["queryName"]=> 
      NULL 
     } 
     [7]=> 
     object(cmisPropertyId)#146 (5) { 
      ["value"]=> 
      array(1) { 
      [0]=> 
      string(60) "workspace://SpacesStore/b461d5ac-5df9-48ec-84ed-03257c411227" 
      } 
      ["propertyDefinitionId"]=> 
      object(stdClass)#133 (0) { 
      } 
      ["localName"]=> 
      NULL 
      ["displayName"]=> 
      NULL 
      ["queryName"]=> 
      NULL 
     } 
     } 
     ["allowableActions"]=> 
     NULL 
     ["relationship"]=> 
     NULL 
     ["changeEventInfo"]=> 
     NULL 
     ["acl"]=> 
     NULL 
     ["exactACL"]=> 
     NULL 
     ["policyIds"]=> 
     NULL 
     ["rendition"]=> 
     NULL 
     ["any"]=> 
     NULL 
    } 
    ["pathSegment"]=> 
    NULL 
    ["any"]=> 
    NULL 
    } 
... 

很明显,我无法更改WSDL文件。我已阅读了一些注释,指出PHP SOAP不支持SOAP消息中的属性数据。如果这是真的,那么PHP SOAP对于这个应用程序几乎没有用处。

有没有人有一个想法如何解析与内置的SOAP扩展的响应?或者我需要寻求一种完全绕过PHP SOAP功能的解决方案?

+0

http://*.com/a/8078127/684934看起来像一个可能的解决方案。可能比使用一般的XML解析器更容易。 – bdares 2012-08-01 17:01:11

+0

是的,我之前查看过这个响应,实际上它建议应用一个类图。我已经这样做了,结果没有变化。 – karstene 2012-08-02 09:01:04

我终于能够自己跟踪这个。

的问题是在WSDL文件中的属性类型定义:

<xs:attribute name="propertyDefinitionId" type="xs:anySimpleType" /> 

的PHP解析器WSDL不喜欢的xs:anySimpleType类型。用替换为xs:string使整个问题消失。也许这是PHP中的一个错误。