1

我正在尝试对.cxml文件进行非常简单的操作。如您所知,它基本上是一个.xml文件。这是我为测试应用程序而创建的示例文件:

<?xml version="1.0" encoding="utf-8"?>
<Collection xmlns:p="http://schemas.microsoft.com/livelabs/pivot/collection/2009" SchemaVersion="1.0" Name="Actresses" xmlns="http://schemas.microsoft.com/collection/metadata/2009">
  <FacetCategories>
    <FacetCategory Name="Nationality" Type="LongString" p:IsFilterVisible="true" p:IsWordWheelVisible="true" p:IsMetaDataVisible="true" />
  </FacetCategories>
<!-- Other entries-->
  <Items ImgBase="Actresses_files\go144bwo.0ao.xml" HrefBase="http://www.imdb.com/name/">    
    <Item Id="2" Img="#2" Name="Anna Karina" Href="nm0439344/">
      <Description> She is a nice girl</Description>
      <Facets>
        <Facet Name="Nationality">
          <LongString Value="Danish" />
        </Facet>
      </Facets>
    </Item>    
  </Items>
<!-- Other entries-->
</Collection>

我无法获得任何功能简单的代码,例如:

XDocument document = XDocument.Parse(e.Result);
foreach (XElement x in document.Descendants("Item"))
{
...
}

对泛型的测试xml正在运行。该cxml文件已正确加载到文档中。

一边看表情:

document.Descendants("Item"), 结果

答案是:

空的“枚举没有结果”字符串

关于可能是什么错误的任何提示?我还添加了快速查看以获取 Facet、Facet 等的后代,但枚举中没有结果。这显然不会发生在xml我用于测试的通用文件中。这是我遇到的问题.cxml

4

2 回答 2

0

基本上,您的 XML 定义了一个具有以下xmlns="http://schemas.microsoft.com/collection/metadata/2009"属性的默认命名空间:

这意味着您需要完全限定您的后代查询,例如:

XDocument document = XDocument.Parse(e.Result);
foreach (XElement x in document.Descendants("{http://schemas.microsoft.com/collection/metadata/2009}Item"))
{
...
}

如果您从 XML 中删除默认名称空间,您的代码实际上可以按原样工作,但这不是本练习的目的。

于 2012-01-11T16:21:22.107 回答
0

有关基于 LINQ 的 CXML 文件解析,请参阅http://github.com/Zoomicon/Metadata.CXML源代码下的 Metadata.CXML 项目。

另请参阅http://github.com/Zoomicon/ClipFlair.Metadata上的ClipFlair.Metadata 项目,以解析一个 CXML 自定义方面

BTW, at http://ClipFlair.codeplex.com can checkout the ClipFlair.Gallery project for how to author ASP.net web-based forms to edit metadata fragments (parts of CXML files) and merge them together in a single one (that you then convert periodically to DeepZoom CXML with PAuthor tool from http://pauthor.codeplex.com).

If anyone is interested in doing nesting (hierarchy) of CXML collections see http://github.com/Zoomicon/Trafilm.Metadata and http://github.com/Zoomicon/Trafilm.Gallery

于 2013-11-04T13:32:52.443 回答