我试图对.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(“项目”),结果
答案是:
空“枚举不产生结果”字符串
对于什么可能是错误有任何提示吗?我还添加了一个快速查看,以获得方面、面等的从属项,但是在枚举中没有结果。显然,在我用于测试的通用xml文件中不会出现这种情况。这是我对.cxml的一个问题。
发布于 2012-01-11 16:21:22
基本上,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中删除默认的名称空间,您的代码实际上是按-原样工作的,但这不是练习的目的。
发布于 2013-11-04 13:32:52
有关基于LINQ的CXML文件解析,请参见http://github.com/Zoomicon/Metadata.CXML源代码下的http://github.com/Zoomicon/Metadata.CXML项目。
也请参阅http://github.com/Zoomicon/ClipFlair.Metadata上的http://github.com/Zoomicon/ClipFlair.Metadata项目来解析自己的CXML自定义方面
顺便说一句,http://ClipFlair.codeplex.com可以签出ClipFlair.Gallery项目,了解如何编写基于ASP.net web的表单来编辑元数据片段( CXML文件的一部分),并将它们合并到一个单独的表单中(然后通过http://pauthor.codeplex.com的PAuthor工具定期将其转换为DeepZoom CXML )。
如果有人对CXML集合进行嵌套(层次结构)感兴趣,请参阅http://github.com/Zoomicon/Trafilm.Metadata和http://github.com/Zoomicon/Trafilm.Gallery。
https://stackoverflow.com/questions/8818783
复制相似问题