2013-12-17 182 views
1

我的目的是使用PHP脚本,来实现这一点,我在下面终端执行卷曲声明基本上列出露天场地中的文件夹,露天:从CMIS获取数据响应

curl -u admin:admin123 http://localhost:8080/alfresco/service/api/node/workspace/SpacesStore/02f9530f-a1b1-4d6d-b479-b5355692b8e2/children 

,我也得到了响应,下面,

<?xml version="1.0" encoding="UTF-8"?> 
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:app="http://www.w3.org/2007/app" xmlns:cmisra="http://docs.oasis-open.org/ns/cmis/restatom/200908/" xmlns:cmis="http://docs.oasis-open.org/ns/cmis/core/200908/" xmlns:alf="http://www.alfresco.org" xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/"> 
<author><name>admin</name></author> 
<generator version="4.2.0 (4576)">Alfresco (Community)</generator> 
<icon>http://localhost:8080/alfresco/images/logo/AlfrescoLogo16.ico</icon> 
<id>urn:uuid:02f9530f-a1b1-4d6d-b479-b5355692b8e2-children</id> 
<link rel="service" href="http://localhost:8080/alfresco/service/cmis"/> 
<link rel="self" href="http://localhost:8080/alfresco/service/api/node/workspace/SpacesStore/02f9530f-a1b1-4d6d-b479-b5355692b8e2/children"/> 
<link rel="via" href="http://localhost:8080/alfresco/service/cmis/s/workspace:SpacesStore/i/02f9530f-a1b1-4d6d-b479-b5355692b8e2"/> 
<link rel="up" href="http://localhost:8080/alfresco/service/cmis/s/workspace:SpacesStore/i/4046a051-6cde-4049-a222-53365ac4fbd4/children" type="application/atom+xml;type=feed"/> 
<link rel="down" href="http://localhost:8080/alfresco/service/cmis/s/workspace:SpacesStore/i/02f9530f-a1b1-4d6d-b479-b5355692b8e2/descendants" type="application/cmistree+xml"/> 
<link rel="http://docs.oasis-open.org/ns/cmis/link/200908/foldertree" href="http://localhost:8080/alfresco/service/cmis/s/workspace:SpacesStore/i/02f9530f-a1b1-4d6d-b479-b5355692b8e2/tree" type="application/atom+xml;type=feed"/> 
<link rel="first" href="http://localhost:8080/alfresco/service/api/node/workspace/SpacesStore/02f9530f-a1b1-4d6d-b479-b5355692b8e2/children?pageNo=1&amp;pageSize=-1&amp;guest=&amp;format=atomfeed" type="application/atom+xml;type=feed"/> 
<link rel="last" href="http://localhost:8080/alfresco/service/api/node/workspace/SpacesStore/02f9530f-a1b1-4d6d-b479-b5355692b8e2/children?pageNo=1&amp;pageSize=-1&amp;guest=&amp;format=atomfeed" type="application/atom+xml;type=feed"/> 
<title>mysite Children</title> 
<updated>2013-12-11T17:11:32.963+05:30</updated> 
<opensearch:totalResults>1</opensearch:totalResults> 
<opensearch:startIndex>0</opensearch:startIndex> 
<opensearch:itemsPerPage>-1</opensearch:itemsPerPage> 
<cmisra:numItems>1</cmisra:numItems> 
<entry> 
<author><name>admin</name></author> 
<content src="http://localhost:8080/alfresco/service/cmis/s/workspace:SpacesStore/i/863dba18-b564-4042-b9a9-e26d83eee13f/content"/><id>urn:uuid:863dba18-b564-4042-b9a9-e26d83eee13f</id> 
<link rel="self" href="http://localhost:8080/alfresco/service/cmis/s/workspace:SpacesStore/i/863dba18-b564-4042-b9a9-e26d83eee13f"/> 
<link rel="edit" href="http://localhost:8080/alfresco/service/cmis/s/workspace:SpacesStore/i/863dba18-b564-4042-b9a9-e26d83eee13f"/> 
<link rel="http://docs.oasis-open.org/ns/cmis/link/200908/allowableactions" href="http://localhost:8080/alfresco/service/cmis/s/workspace:SpacesStore/i/863dba18-b564-4042-b9a9-e26d83eee13f/allowableactions"/> 
<link rel="http://docs.oasis-open.org/ns/cmis/link/200908/relationships" href="http://localhost:8080/alfresco/service/cmis/s/workspace:SpacesStore/i/863dba18-b564-4042-b9a9-e26d83eee13f/rels"/> 
<link rel="http://docs.oasis-open.org/ns/cmis/link/200908/policies" href="http://localhost:8080/alfresco/service/cmis/s/workspace:SpacesStore/i/863dba18-b564-4042-b9a9-e26d83eee13f/pols"/> 
<link rel="http://docs.oasis-open.org/ns/cmis/link/200908/acl" href="http://localhost:8080/alfresco/service/cmis/s/workspace:SpacesStore/i/863dba18-b564-4042-b9a9-e26d83eee13f/acl"/> 
<link rel="up" href="http://localhost:8080/alfresco/service/cmis/s/workspace:SpacesStore/i/02f9530f-a1b1-4d6d-b479-b5355692b8e2" type="application/atom+xml;type=entry"/> 
<link rel="down" href="http://localhost:8080/alfresco/service/cmis/s/workspace:SpacesStore/i/863dba18-b564-4042-b9a9-e26d83eee13f/children" type="application/atom+xml;type=feed"/> 
<link rel="down" href="http://localhost:8080/alfresco/service/cmis/s/workspace:SpacesStore/i/863dba18-b564-4042-b9a9-e26d83eee13f/descendants" type="application/cmistree+xml"/> 
<link rel="http://docs.oasis-open.org/ns/cmis/link/200908/foldertree" href="http://localhost:8080/alfresco/service/cmis/s/workspace:SpacesStore/i/863dba18-b564-4042-b9a9-e26d83eee13f/tree" type="application/atom+xml;type=feed"/> 
<link rel="describedby" href="http://localhost:8080/alfresco/service/cmis/type/cmis:folder"/> 
<link rel="service" href="http://localhost:8080/alfresco/service/cmis"/> 
<published>2013-12-11T17:11:32.522+05:30</published> 
<summary>Document Library</summary> 
<title>documentLibrary</title> 
<updated>2013-12-13T11:50:55.893+05:30</updated> 
<app:edited>2013-12-13T11:50:55.893+05:30</app:edited> 
<alf:icon>http://localhost:8080/alfresco/images/icons/space-icon-default-16.gif</alf:icon> 
<cmisra:object> 
<cmis:properties> 
<cmis:propertyId propertyDefinitionId="cmis:allowedChildObjectTypeIds" displayName="Allowed Child Object Types Ids" queryName="cmis:allowedChildObjectTypeIds"/> 
<cmis:propertyId propertyDefinitionId="cmis:objectTypeId" displayName="Object Type Id" queryName="cmis:objectTypeId"><cmis:value>cmis:folder</cmis:value></cmis:propertyId> 
<cmis:propertyString propertyDefinitionId="cmis:path" displayName="Path" queryName="cmis:path"><cmis:value>/Sites/mysite/documentLibrary</cmis:value></cmis:propertyString> 
<cmis:propertyString propertyDefinitionId="cmis:name" displayName="Name" queryName="cmis:name"><cmis:value>documentLibrary</cmis:value></cmis:propertyString> 
<cmis:propertyDateTime propertyDefinitionId="cmis:creationDate" displayName="Creation Date" queryName="cmis:creationDate"><cmis:value>2013-12-11T17:11:32.522+05:30</cmis:value></cmis:propertyDateTime> 
<cmis:propertyString propertyDefinitionId="cmis:changeToken" displayName="Change token" queryName="cmis:changeToken"/> 
<cmis:propertyString propertyDefinitionId="cmis:lastModifiedBy" displayName="Last Modified By" queryName="cmis:lastModifiedBy"><cmis:value>admin</cmis:value></cmis:propertyString> 
<cmis:propertyString propertyDefinitionId="cmis:createdBy" displayName="Created by" queryName="cmis:createdBy"><cmis:value>admin</cmis:value></cmis:propertyString> 
<cmis:propertyId propertyDefinitionId="cmis:objectId" displayName="Object Id" queryName="cmis:objectId"><cmis:value>workspace://SpacesStore/863dba18-b564-4042-b9a9-e26d83eee13f</cmis:value></cmis:propertyId> 
<cmis:propertyId propertyDefinitionId="alfcmis:nodeRef" displayName="Alfresco Node Ref" queryName="alfcmis:nodeRef"/> 
<cmis:propertyId propertyDefinitionId="cmis:baseTypeId" displayName="Base Type Id" queryName="cmis:baseTypeId"><cmis:value>cmis:folder</cmis:value></cmis:propertyId> 
<cmis:propertyId propertyDefinitionId="cmis:parentId" displayName="Parent Id" queryName="cmis:parentId"><cmis:value>workspace://SpacesStore/02f9530f-a1b1-4d6d-b479-b5355692b8e2</cmis:value></cmis:propertyId> 
<cmis:propertyDateTime propertyDefinitionId="cmis:lastModificationDate" displayName="Last Modified Date" queryName="cmis:lastModificationDate"><cmis:value>2013-12-13T11:50:55.893+05:30</cmis:value></cmis:propertyDateTime> 
<alf:aspects> 
<alf:appliedAspects>P:sys:localized</alf:appliedAspects> 
<alf:appliedAspects>P:cm:titled</alf:appliedAspects> 
<alf:appliedAspects>P:cm:ownable</alf:appliedAspects> 
<alf:appliedAspects>P:cm:tagscope</alf:appliedAspects> 
<alf:appliedAspects>P:st:siteContainer</alf:appliedAspects> 
<alf:properties> 
<cmis:propertyString propertyDefinitionId="cm:description" displayName="Description" queryName="cm:description"><cmis:value>Document Library</cmis:value></cmis:propertyString> 
<cmis:propertyString propertyDefinitionId="cm:title" displayName="Title" queryName="cm:title"/> 
<cmis:propertyString propertyDefinitionId="cm:owner" displayName="Owner" queryName="cm:owner"><cmis:value>admin</cmis:value></cmis:propertyString> 
<cmis:propertyString propertyDefinitionId="cm:tagScopeSummary" displayName="Tag Summary" queryName="cm:tagScopeSummary"/> 
<cmis:propertyString propertyDefinitionId="st:componentId" displayName="Component Id" queryName="st:componentId"><cmis:value>documentLibrary</cmis:value></cmis:propertyString> 
</alf:properties> 
</alf:aspects> 
</cmis:properties> 
</cmisra:object> 
<cmisra:pathSegment>documentLibrary</cmisra:pathSegment> 
</entry> 

我如何获取PHP中的子数据?即基本上是标题'documentLibrary',它是objectId。

回答

0

如果你的使用情况很简单,只要你所描述的东西,你可以使用XPath在PHP查询你正在处理的数据。

下面是XPath查询,你可以使用:

选择“标题”元素(我建议选择propertyString CMIS:名称,而不是 - 虽然CMIS规范指定CMIS:名称必须在原子设置:标题元素,我发现那里的仓库不设置标题元素,因为它在CMIS规范中定义的情况下)

//cmis:propertyString[contains(@propertyDefinitionId, 'cmis:name')][1]/cmis:value/text() 

选择CMIS:OBJECTID

//cmis:propertyId[contains(@propertyDefinitionId, 'cmis:objectId')][1]/cmis:value[1]/text() 

如果您通过CMIS与更多复杂用例进行交互,请查看Apache Chemistry CMIS PHP Client(http://chemistry.apache.org/php/phpclient.html)以获取健壮的客户端库,并查看客户端库是否适合您的需求。

编辑 - 一个简单的例子,把它放在一起......

// Load the XML String into a SimpleXMLElement 
$sxe = new SimpleXMLElement($xmlResponse); 

// Optional but good practice - register namespaces 
$sxe->registerXPathNamespace('cmis', 'http://docs.oasis-open.org/ns/cmis/core/200908/'); 

// Execute XPath Query 
$result = $sxe->xpath("//cmis:propertyString[contains(@propertyDefinitionId, 'cmis:name')][1]/cmis:value/text()"); 

// Do something with the result. 
echo $result[0] // For XPath above this will print: "documentLibrary" 
+0

谢谢你的回复。我不知道cmis和它的处理。请问,如果我现在问一个无意义的问题。执行curl命令后得到的响应将保存在变量中,例如$ response。我怎样才能得到这个变量的值。 – Rumi

+0

Rumi,我已根据您的评论更新了我的答案。这个更新只是一个简单的例子。如果您正在做更多的事情,我们正在讨论,我强烈建议查看Apache Chemistry PHP Client库。 – gbags