private void ExportDatasetToXML(String databaseName, String outputXmlFile)
{
// Open the source geodatabase.
IWorkspaceFactory workspaceFactory = new AccessWorkspaceFactoryClass();
IWorkspace workspace = workspaceFactory.OpenFromFile(databaseName, 0);
// Retrieve the first feature dataset from the workspace.
IEnumDatasetName enumDatasetName = workspace.get_DatasetNames
(esriDatasetType.esriDTFeatureDataset);
enumDatasetName.Reset();
IName featureDatasetName = (IName)enumDatasetName.Next();
if (featureDatasetName == null)
{
throw new ArgumentException(
"No feature datasets exist in the specified geodatabase.");
}
// Create a new enumerator and add the feature dataset name.
IEnumNameEdit enumNameEdit = new NamesEnumeratorClass();
enumNameEdit.Add(featureDatasetName);
IEnumName enumName = (IEnumName)enumNameEdit;
// Create a scratch workspace factory.
IScratchWorkspaceFactory scratchWorkspaceFactory = new
ScratchWorkspaceFactoryClass();
IWorkspace scratchWorkspace =
scratchWorkspaceFactory.CreateNewScratchWorkspace();
IDataset dataset = (IDataset)scratchWorkspace;
IName workspaceName = dataset.FullName;
// Create a GeoDBDataTransfer object and create a name mapping.
IGeoDBDataTransfer geoDBDataTransfer = new GeoDBDataTransferClass();
IEnumNameMapping enumNameMapping = null;
Boolean hasConflicts = geoDBDataTransfer.GenerateNameMapping(enumName,
workspaceName, out enumNameMapping);
if (hasConflicts)
{
// TODO: Handle this in a way appropriate to your application.
}
// Create an exporter and export the dataset with binary geometry, not compressed,
// and including metadata.
IGdbXmlExport gdbXmlExport = new GdbExporterClass();
gdbXmlExport.ExportDatasets(enumNameMapping, outputXmlFile, true, false, true)
;
}
private void XmlImportWS(string workspacePathname, string dbName, string
inXmlFile)
{
// Create an Access database (dbName) at the workspacePathname location.
IWorkspaceFactory workspaceFactory = new AccessWorkspaceFactoryClass();
IWorkspaceName workspaceName = workspaceFactory.Create(workspacePathname,
dbName, null, 0);
// Open the geodatabase.
IName name = (IName)workspaceName;
IWorkspace workspace = (IWorkspace)name.Open(); // Explicit Cast
// Create a GdbImporter.
IGdbXmlImport gdbXmlImport = new GdbImporterClass();
// Read schema section from the XML file.
// Note: enumNameMapping is initialized to nothing and its value is set 'by ref' with a call to the GenerateNameMapping method.
IEnumNameMapping enumNameMapping = null;
gdbXmlImport.GenerateNameMapping(inXmlFile, workspace, out enumNameMapping);
// Create the workspace schema and load the data.
gdbXmlImport.ImportWorkspace(inXmlFile, enumNameMapping, workspace, false);
}