2012-08-29 84 views
0

我有以下XML:如何選擇節點

<?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>Me</name></author> 
<generator version="3.4.7 (572)">Alfresco (Enterprise)</generator> 
<icon>http://xxxxx/alfresco/images/logo/AlfrescoLogo16.ico</icon> 
<id>urn:uuid:0d9b7b51-a696-4d79-85ed-9c3511e0b812-children</id> 
<link rel="service" href="http://xxxxx/alfresco/service/cmis"/> 
<link rel="self" href="http://xxxxx/alfresco/service/cmis/s/workspace:SpacesStore/i/0d9b7b51-a696-4d79-85ed-9c3511e0b812/children"/> 
<link rel="via" href="http://xxxxx/alfresco/service/cmis/s/workspace:SpacesStore/i/0d9b7b51-a696-4d79-85ed-9c3511e0b812"/> 
<link rel="up" href="http://xxxxx/alfresco/service/cmis/s/workspace:SpacesStore/i/4d4117c4-beaf-4065-9a45-749928506507/children" type="application/atom+xml;type=feed"/> 
<link rel="down" href="http://xxxxx/alfresco/service/cmis/s/workspace:SpacesStore/i/0d9b7b51-a696-4d79-85ed-9c3511e0b812/descendants" type="application/cmistree+xml"/> 
<link rel="http://docs.oasis-open.org/ns/cmis/link/200908/foldertree" href="http://xxxxx/alfresco/service/cmis/s/workspace:SpacesStore/i/0d9b7b51-a696-4d79-85ed-9c3511e0b812/tree" type="application/atom+xml;type=feed"/> 
<link rel="first" href="http://xxxxx/alfresco/service/cmis/s/workspace:SpacesStore/i/0d9b7b51-a696-4d79-85ed-9c3511e0b812/children?pageNo=1&amp;pageSize=-1&amp;guest=&amp;format=atomfeed" type="application/atom+xml;type=feed"/> 
<link rel="last" href="http://xxxxx/alfresco/service/cmis/s/workspace:SpacesStore/i/0d9b7b51-a696-4d79-85ed-9c3511e0b812/children?pageNo=1&amp;pageSize=-1&amp;guest=&amp;format=atomfeed" type="application/atom+xml;type=feed"/> 
<title>Directory</title> 
<updated>2012-08-03T08:55:10.413+02:00</updated> 
<opensearch:totalResults>3</opensearch:totalResults> 
<opensearch:startIndex>0</opensearch:startIndex> 
<opensearch:itemsPerPage>-1</opensearch:itemsPerPage> 
<cmisra:numItems>3</cmisra:numItems> 
<entry> 
<author><name>Me</name></author> 
<content type="application/vnd.openxmlformats-officedocument.wordprocessingml.document" src="http://xxxxx/alfresco/service/cmis/s/workspace:SpacesStore/i/a8df77ad-7542-4380-819e-97bcb652c39a/content.docx"/><id>urn:uuid:a8df77ad-7542-4380-819e-97bcb652c39a</id> 
<link rel="self" href="http://xxxxx/alfresco/service/cmis/s/workspace:SpacesStore/i/a8df77ad-7542-4380-819e-97bcb652c39a"/> 
<link rel="enclosure" href="http://xxxxx/alfresco/service/cmis/s/workspace:SpacesStore/i/a8df77ad-7542-4380-819e-97bcb652c39a/content.docx" type="application/vnd.openxmlformats-officedocument.wordprocessingml.document"/> 
<link rel="edit" href="http://xxxxx/alfresco/service/cmis/s/workspace:SpacesStore/i/a8df77ad-7542-4380-819e-97bcb652c39a"/> 
<link rel="edit-media" href="http://xxxxx/alfresco/service/cmis/s/workspace:SpacesStore/i/a8df77ad-7542-4380-819e-97bcb652c39a/content.docx" type="application/vnd.openxmlformats-officedocument.wordprocessingml.document"/> 
<link rel="http://docs.oasis-open.org/ns/cmis/link/200908/allowableactions" href="http://xxxxx/alfresco/service/cmis/s/workspace:SpacesStore/i/a8df77ad-7542-4380-819e-97bcb652c39a/allowableactions"/> 
<link rel="http://docs.oasis-open.org/ns/cmis/link/200908/relationships" href="http://xxxxx/alfresco/service/cmis/s/workspace:SpacesStore/i/a8df77ad-7542-4380-819e-97bcb652c39a/rels"/> 
<link rel="http://docs.oasis-open.org/ns/cmis/link/200908/policies" href="http://xxxxx/alfresco/service/cmis/s/workspace:SpacesStore/i/a8df77ad-7542-4380-819e-97bcb652c39a/pols"/> 
<link rel="http://docs.oasis-open.org/ns/cmis/link/200908/acl" href="http://xxxxx/alfresco/service/cmis/s/workspace:SpacesStore/i/a8df77ad-7542-4380-819e-97bcb652c39a/acl"/> 
<link rel="up" href="http://xxxxx/alfresco/service/cmis/s/workspace:SpacesStore/i/a8df77ad-7542-4380-819e-97bcb652c39a/parents" type="application/atom+xml;type=feed"/> 
<link rel="version-history" href="http://xxxxx/alfresco/service/cmis/s/workspace:SpacesStore/i/a8df77ad-7542-4380-819e-97bcb652c39a/versions"/> 
<link rel="current-version" href="http://xxxxx/alfresco/service/cmis/s/workspace:SpacesStore/i/a8df77ad-7542-4380-819e-97bcb652c39a?returnVersion=latest"/> 
<link rel="describedby" href="http://xxxxx/alfresco/service/cmis/type/cmis:document"/> 
<link rel="service" href="http://xxxxx/alfresco/service/cmis"/> 
<published>2011-09-27T16:24:09.302+02:00</published> 
<summary>Test.docx</summary> 
<title>Test.docx</title> 
<updated>2011-09-27T16:24:14.864+02:00</updated> 
<app:edited>2011-09-27T16:24:14.864+02:00</app:edited> 
<alf:icon>http://xxxxx/alfresco/images/filetypes/docx.gif</alf:icon> 
<cmisra:object> 
<cmis:properties> 
<cmis:propertyBoolean propertyDefinitionId="cmis:isLatestMajorVersion" displayName="Is Latest Major Version" queryName="cmis:isLatestMajorVersion"><cmis:value>false</cmis:value></cmis:propertyBoolean> 
<cmis:propertyInteger propertyDefinitionId="cmis:contentStreamLength" displayName="Content Stream Length" queryName="cmis:contentStreamLength"><cmis:value>245939</cmis:value></cmis:propertyInteger> 
<cmis:propertyId propertyDefinitionId="cmis:contentStreamId" displayName="Content Stream Id" queryName="cmis:contentStreamId"><cmis:value>store://2011/9/27/16/24/d18d00be-6abd-4b20-9ef0-88f336a62cf0.bin</cmis:value></cmis:propertyId> 
<cmis:propertyString propertyDefinitionId="cmis:versionSeriesCheckedOutBy" displayName="Version Series Checked Out By" queryName="cmis:versionSeriesCheckedOutBy"/> 
<cmis:propertyId propertyDefinitionId="cmis:objectTypeId" displayName="Object Type Id" queryName="cmis:objectTypeId"><cmis:value>cmis:document</cmis:value></cmis:propertyId> 
<cmis:propertyId propertyDefinitionId="cmis:versionSeriesCheckedOutId" displayName="Version Series Checked Out Id" queryName="cmis:versionSeriesCheckedOutId"/> 
<cmis:propertyString propertyDefinitionId="cmis:name" displayName="Name" queryName="cmis:name"><cmis:value>Test.docx</cmis:value></cmis:propertyString> 
<cmis:propertyString propertyDefinitionId="cmis:contentStreamMimeType" displayName="Content Stream MIME Type" queryName="cmis:contentStreamMimeType"><cmis:value>application/vnd.openxmlformats-officedocument.wordprocessingml.document</cmis:value></cmis:propertyString> 
<cmis:propertyId propertyDefinitionId="cmis:versionSeriesId" displayName="Version series id" queryName="cmis:versionSeriesId"><cmis:value>workspace://SpacesStore/a8df77ad-7542-4380-819e-97bcb652c39a</cmis:value></cmis:propertyId> 
<cmis:propertyDateTime propertyDefinitionId="cmis:creationDate" displayName="Creation Date" queryName="cmis:creationDate"><cmis:value>2011-09-27T16:24:09.302+02:00</cmis:value></cmis:propertyDateTime> 
<cmis:propertyString propertyDefinitionId="cmis:changeToken" displayName="Change token" queryName="cmis:changeToken"/> 
<cmis:propertyString propertyDefinitionId="cmis:versionLabel" displayName="Version Label" queryName="cmis:versionLabel"><cmis:value>1.2</cmis:value></cmis:propertyString> 
<cmis:propertyBoolean propertyDefinitionId="cmis:isLatestVersion" displayName="Is Latest Version" queryName="cmis:isLatestVersion"><cmis:value>true</cmis:value></cmis:propertyBoolean> 
<cmis:propertyBoolean propertyDefinitionId="cmis:isVersionSeriesCheckedOut" displayName="Is Version Series Checked Out" queryName="cmis:isVersionSeriesCheckedOut"><cmis:value>false</cmis:value></cmis:propertyBoolean> 
<cmis:propertyString propertyDefinitionId="cmis:lastModifiedBy" displayName="Last Modified By" queryName="cmis:lastModifiedBy"><cmis:value>Me</cmis:value></cmis:propertyString> 
<cmis:propertyString propertyDefinitionId="cmis:createdBy" displayName="Created by" queryName="cmis:createdBy"><cmis:value>Me</cmis:value></cmis:propertyString> 
<cmis:propertyString propertyDefinitionId="cmis:checkinComment" displayName="Checkin Comment" queryName="cmis:checkinComment"/> 
<cmis:propertyId propertyDefinitionId="cmis:objectId" displayName="Object Id" queryName="cmis:objectId"><cmis:value>workspace://SpacesStore/a8df77ad-7542-4380-819e-97bcb652c39a</cmis:value></cmis:propertyId> 
<cmis:propertyBoolean propertyDefinitionId="cmis:isImmutable" displayName="Is Immutable" queryName="cmis:isImmutable"><cmis:value>false</cmis:value></cmis:propertyBoolean> 
<cmis:propertyBoolean propertyDefinitionId="cmis:isMajorVersion" displayName="Is Major Version" queryName="cmis:isMajorVersion"><cmis:value>false</cmis:value></cmis:propertyBoolean> 
<cmis:propertyId propertyDefinitionId="cmis:baseTypeId" displayName="Base Type Id" queryName="cmis:baseTypeId"><cmis:value>cmis:document</cmis:value></cmis:propertyId> 
<cmis:propertyString propertyDefinitionId="cmis:contentStreamFileName" displayName="Content Stream Filename" queryName="cmis:contentStreamFileName"><cmis:value>Test.docx</cmis:value></cmis:propertyString> 
<cmis:propertyDateTime propertyDefinitionId="cmis:lastModificationDate" displayName="Last Modified Date" queryName="cmis:lastModificationDate"><cmis:value>2011-09-27T16:24:14.864+02:00</cmis:value></cmis:propertyDateTime> 
<alf:aspects> 
<alf:appliedAspects>P:rn:renditioned</alf:appliedAspects> 
<alf:appliedAspects>P:cm:author</alf:appliedAspects> 
<alf:properties> 
<cmis:propertyString propertyDefinitionId="cm:author" displayName="Auteur" queryName="cm:author"><cmis:value>Me</cmis:value></cmis:propertyString> 
</alf:properties> 
</alf:aspects> 
</cmis:properties> 
</cmisra:object> 
<cmisra:pathSegment>Test.docx</cmisra:pathSegment> 
</entry> 
</feed> 

我想選擇「進入」節點,但我無法得到它的工作。

XmlDocument rssDoc = new XmlDocument();    
    XmlNamespaceManager manager = new XmlNamespaceManager(rssDoc.NameTable); 
    manager.AddNamespace("atom", "http://www.w3.org/2005/Atom"); 
    manager.AddNamespace("app", "http://www.w3.org/2007/app"); 
    manager.AddNamespace("cmisra", "http://docs.oasis-open.org/ns/cmis/restatom/200908/"); 
    manager.AddNamespace("cmis", "http://docs.oasis-open.org/ns/cmis/core/200908/"); 
    manager.AddNamespace("alf", "http://www.alfresco.org"); 
    manager.AddNamespace("opensearch", "http://a9.com/-/spec/opensearch/1.1/"); 
    rssDoc.Load(rssStream); 

    XmlNodeList rssItems = rssDoc.SelectNodes("//atom:entry", manager); 

出了什麼問題?我嘗試了不同的xpath,但沒有工作。 我從調用Alfresco web服務獲取rss。 我編輯了原本比較長的xml。

+0

你能夠使用LINQ to XML嗎?我的經驗是,它通常要簡單得多... –

+0

你有沒有試過// *:入口?這樣,你可能會知道它是否是一個命名空間綁定問題。 –

+0

此外,您是否嘗試在構建命名空間管理器之前加載文檔,如下所示:http://support.microsoft.com/kb/316913?只是一個猜測。 –

回答

2

您最好使用CMIS客戶端庫,而不是嘗試自己手動解析AtomPub XML。 Apache Chemistry有一個名爲DotCMIS的C#客戶端。

0

謝謝大家的幫助!

答案是我很愚蠢,因爲我沒有調用正確的web服務,因此我沒有得到所有我發佈的xml(我通過手動獲取)。 一旦糾正,它就像一個魅力。