Pivotviewer's .cxml parsing

1k views Asked by At

I'm trying to do very simple operations on a .cxml file. As you know it's basically an .xml file. This is a sample file I created to test the application:

<?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>

I can't get any functioning simple code like:

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

The test on a generic xml is working. The cxml file is correctly loaded in document.

While watching the expression:

document.Descendants("Item"), results

the answer is:

Empty "Enumeration yielded no results" string

Any hint on what can be the error? I've also add a quick look to get Descendants of Facet, Facets, etc., but there are no results in the enumeration. This obviously doesn't happen with a generic xml file I used for testing. It's a problem I have with .cxml.

2

There are 2 answers

0
iCollect.it Ltd On BEST ANSWER

Basically your XML defines a default namespace with the xmlns="http://schemas.microsoft.com/collection/metadata/2009" attribute:

That means you need to fully qualify your Descendants query e.g.:

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

If you remove the default namespace from the XML your code actually works as-is, but that is not the aim of the exercise.

0
George Birbilis On

See Metadata.CXML project under http://github.com/Zoomicon/Metadata.CXML sourcecode for LINQ-based parsing of CXML files.

Also see ClipFlair.Metadata project at http://github.com/Zoomicon/ClipFlair.Metadata for parsing one's CXML custom facets too

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