如何选择节点

时间:2012-08-29 14:56:16

标签: c# xml xml-parsing alfresco

我有以下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>

我正在尝试选择'entry'节点,但我无法让它工作。

    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 webservices来获取rss。 我编辑了最初更长的xml。

3 个答案:

答案 0 :(得分:2)

您可能最好使用CMIS客户端库,而不是尝试自己手动解析AtomPub XML。 Apache Chemistry有一个名为DotCMIS的C#客户端。

答案 1 :(得分:0)

尝试

//*[local-name()='entry']

这将选择符合名称&#39;条目&#39;的所有元素。无视命名空间。

答案 2 :(得分:0)

谢谢大家的帮助!

答案是我是愚蠢的,因为我没有调用正确的Web服务,因此我没有得到我发布的所有xml(我手工获得)。 一旦纠正,它就像一个魅力。