PivotViewerの.cxml解析
-
27-10-2019 - |
質問
私はaで非常に簡単な操作をしようとしています .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")、結果
答えは次のとおりです。
空の「列挙は結果が得られませんでした」文字列
何がエラーになるかについてのヒントはありますか?また、ファセット、ファセットなどの子孫を得るために簡単な外観を追加しますが、列挙には結果はありません。これは明らかにジェネリックでは起こりません xml
テストに使用したファイル。それは私が抱えている問題です .cxml
.
解決
基本的に、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からデフォルトの名前空間を削除すると、実際にはコードが動作しますが、それは演習の目的ではありません。
他のヒント
Metadata.cxmlプロジェクトを参照してください http://github.com/zoomicon/metadata.cxml CXMLファイルのLINQベースの解析用のSourcode。
clipflair.metadataプロジェクトも参照してください http://github.com/zoomicon/clipflair.metadata CXMLカスタムファセットを解析するためにも
ところで、at http://clipflair.codeplex.com clipflair.galleryプロジェクトをチェックアウトして、asp.netのWebベースのフォームを作成してメタデータフラグメント(CXMLファイルの一部)を編集し、単一のものにマージします(その後、定期的にDeepzoom CXMLに変換します。 http://pauthor.codeplex.com).
誰かがCXMLコレクションのネスティング(階層)を実行することに興味がある場合http://github.com/zoomicon/trafilm.metadataとhttp://github.com/zoomicon/trafilm.gallery