How do I create default/minimal valid metadata in ArcObjects

2182
1
Jump to solution
07-25-2014 10:26 AM
MichaelNigbor
New Contributor

We are implementing a set of custom classes that implement GxDatabase, GxDataset (and many other interfaces) so that data can be stored and retrieved in a database. This DB has geospatial capabilities but isn't one of the databases ArcGIS directly supports. For this post, let's call these classes MyDBGxDatabaseClass and MyDBGxDatasetClass.

My task is to implement metadata, which will be stored in a table like it is in the personal geodatabase and SDE databases.  I got MyDBGxDatabaseClass working by implementing IMetadata and IMetadataEdit using the XmlPropertySet class. The only trick was finding a way to create an initial, minimal metadata object for the first call, when nothing is stored in the database.

        public IPropertySet Metadata
        {
            get
            {
                    XmlPropertySet m_Metadata = new XmlPropertySet();
                    string xml = getMetadataXMLFromDB();
                    if( xml == null )
                    {
                         m_Metadata.InitNew();
                    }
                    else
                    {
                         ((IXmlPropertySet2)m_Metadata).SetXml(xml);  
                    }
                    return (IPropertySet)m_Metadata;
            }
            set
            {
                 // Removed for clarity
            }
        }

When this is used on MyDBGxDatabaseClass, ArcCatalog happily consumes the XML created by InitNew(). I can view, edit and save. Life is good.

When this is used on MyDBGxDatasetClass, ArcCatalog returns "The item's XML contains errors." Apparently, ArcCatalog expects different XML for Datasets than for Databases. I've tried lots of alternative XML, including copying metadata XML from a personal geodatabase.  The results are always the same: The item's XML contains errors.

  • Don't all objects, regardless of type, use the same metadata schema?
  • How can I determine what the error(s) is(are)? 

Almost forgot: This is on 10.2.2.

0 Kudos
1 Solution

Accepted Solutions
MichaelNigbor
New Contributor

Problem solved.

The problem turned out to be completely unrelated to Metadata XML. Instead, it was a garden-variety bug in our code.

As ArcCatalog was processing the metadata, it called the ClassID property in the MyDBGxDataset class. This property had a bug in it that resulted in an exception that was returned to ArcCatalog.  This interrupted the metadata processing (probably before the XML even reached the XSLT). 

Once again, led astray by a misleading error message....

View solution in original post

0 Kudos
1 Reply
MichaelNigbor
New Contributor

Problem solved.

The problem turned out to be completely unrelated to Metadata XML. Instead, it was a garden-variety bug in our code.

As ArcCatalog was processing the metadata, it called the ClassID property in the MyDBGxDataset class. This property had a bug in it that resulted in an exception that was returned to ArcCatalog.  This interrupted the metadata processing (probably before the XML even reached the XSLT). 

Once again, led astray by a misleading error message....

0 Kudos