ArcObjects Library Reference  (GeoDatabaseDistributed)    

Xml Export Datasets

[Visual Basic 6.0]

'*** The following example allows you to export datasets to an xml file. ***

'*** This requires an ArcGIS License and you will need to initialize the AoInitialize CoClass ***


Private Sub ExportDS(db As String, XmlFile As String)
 
Dim pWSF As IWorkspaceFactory
Set pWSF = New AccessWorkspaceFactory
 
'*** Open PGDB ***
Dim pWS As IWorkspace
Set pWS = pWSF.OpenFromFile(App.Path + db, 0)
 
Dim pEnumDSN As IEnumDatasetName
Set pEnumDSN = pWS.DatasetNames(esriDTFeatureDataset)
 
pEnumDSN.Reset
 
Dim pEnumEdit As IEnumNameEdit
Set pEnumEdit = New NamesEnumerator
 
'*** QI for Dataset Name ***
Dim pName As IName
Set pName = pEnumDSN.Next
 
pEnumEdit.Add pName
Set pName = pEnumDSN.Next
 
'*** Call GeoDBDataTransfer ***
Dim pGDT As IGeoDBDataTransfer
Set pGDT = New GeoDBDataTransfer
 
Dim pEnumName As IEnumName
Set pEnumName = pEnumEdit
 
'*** Create Scratch Workspace Factory ***
Dim pSWSF As IScratchWorkspaceFactory
Set pSWSF = New ScratchWorkspaceFactory

Dim pScratchWS As IWorkspace
Set pScratchWS = pSWSF.CreateNewScratchWorkspace
 
Dim pDS As IDataset
Set pDS = pScratchWS

Set pName = pDS.FullName
 
'*** Fill IEnumNameMapping ***
Dim pEnumNM As IEnumNameMapping
Dim bHasConflicts As Boolean
bHasConflicts = pGDT.GenerateNameMapping(pEnumName, pName, pEnumNM)
 
' *** Create GdbExporter ***
Dim pExporter As IGdbXmlExport
Set pExporter = New GdbExporter
 
' *** Export Dataset in normalized format and not compressed ***
pExporter.ExportDatasets pEnumNM, XmlFile, False, False, True
 
End Sub

 

'*** Create a commandbutton and copy/paste following code. ***
Private Sub cmdExportDS_Click()
 
Me.MousePointer = vbHourglass
 
'*** Location of PGDB ***
Dim db As String
db = "\GN.mdb"
 
'*** Location of xml file ***
Dim XmlFile As String
XmlFile = App.Path + "\GN.xml"
 
ExportDS db, XmlFile

MsgBox "Exported Dataset to XML.", vbInformation
  
End Sub

[C#]

        #region "Method - Xml Export Dataset.snippet"

        #region "Snippet usage - INTERNAL"
        // TITLE:
        // Method - Xml Export Dataseta

        // DESCRIPTION:
        // Export a dataset to an xml file using the GdbExporter.  The xml file will include all the data and
        // schema information in a binary uncompressed format.

        // HOW TO USE:
        // Call the XmlExportDS method by passing in the following arguments:
        // dbName = a string that contains the path and filename for the Access Geodatabase file (ex: "d:\data\states.mdb")
        // outXmlFile = a string that contains the path and filename for the output workspace XML file (ex: "C:\temp\states.xml")

        // REFERENCES (REQUIRED)
        // ESRI.ArcGIS.DataSourcesGDB
        // ESRI.ArcGIS.Display
        // ESRI.ArcGIS.GeoDatabase
        // ESRI.ArcGIS.GeoDatabaseDistributed
        // ESRI.ArcGIS.System

        // INTENDED PRODUCTS FOR THIS SNIPPET:
        // Desktop, Engine, Server

        // INTERFACES:
        // IWorkspaceFactory, IWorkspace, IEnumDatasetName, IEnumNameEdit, IName, IScratchWorkspaceFactory,
        // IDataset, IGeoDBDataTransfer, IEnumNameMapping, IGdbXmlExport

        // GUID:
        // {9CB604F6-41B9-4504-A219-625562C3B247}
        #endregion

        #region "Snippet usage"
        // TITLE:
        // Method - Xml Export Dataset

        // DESCRIPTION:
        // Export a dataset to an xml file using the GdbExporter.  The xml file will include all the data and
        // schema information in a binary uncompressed format.

        // HOW TO USE:
        // Call the XmlExportDS method by passing in the following arguments:
        // dbName = a string that contains the path and filename for the Access Geodatabase file (ex: "d:\data\states.mdb")
        // outXmlFile = a string that contains the path and filename for the output workspace XML file (ex: "C:\temp\states.xml")

        // REFERENCES (REQUIRED)
        // ESRI.ArcGIS.DataSourcesGDB
        // ESRI.ArcGIS.Display
        // ESRI.ArcGIS.GeoDatabase
        // ESRI.ArcGIS.GeoDatabaseDistributed
        // ESRI.ArcGIS.System
        #endregion

        private void XmlExportDS(string dbName, string outXmlFile)
        {

            // Open geodatabase. Modify the pathnames appropriately
            ESRI.ArcGIS.Geodatabase.IWorkspaceFactory workspaceFactoryCls = new ESRI.ArcGIS.DataSourcesGDB.AccessWorkspaceFactory();
            ESRI.ArcGIS.Geodatabase.IWorkspace workspace = workspaceFactoryCls.OpenFromFile(dbName, 0);

            ESRI.ArcGIS.Geodatabase.IEnumDatasetName enumDatasetName = workspace.get_DatasetNames(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTFeatureDataset);
            enumDatasetName.Reset();
            ESRI.ArcGIS.esriSystem.IEnumNameEdit EnumNameEditCls = new ESRI.ArcGIS.Geodatabase.NamesEnumeratorClass();

            // Implicit Cast for dataset name
            ESRI.ArcGIS.esriSystem.IName name = (ESRI.ArcGIS.esriSystem.IName)enumDatasetName.Next();
            EnumNameEditCls.Add(name);

            // Create a scratch workspace factory
            ESRI.ArcGIS.Geodatabase.IScratchWorkspaceFactory scratchWorkspaceFactoryCls = new ESRI.ArcGIS.DataSourcesGDB.ScratchWorkspaceFactory();
            ESRI.ArcGIS.Geodatabase.IWorkspace scratchWorkspace = scratchWorkspaceFactoryCls.CreateNewScratchWorkspace();

            ESRI.ArcGIS.Geodatabase.IDataset dataset = (ESRI.ArcGIS.Geodatabase.IDataset)scratchWorkspace; // Explicit Cast
            name = dataset.FullName;

            // Call GeoDBDataTransfer
            ESRI.ArcGIS.Geodatabase.IGeoDBDataTransfer geoDBDataTransferCls = new ESRI.ArcGIS.Geodatabase.GeoDBDataTransfer();
            ESRI.ArcGIS.esriSystem.IEnumName enumName = (ESRI.ArcGIS.esriSystem.IEnumName)EnumNameEditCls; // Explicit Cast

            // Fill IEnumNameMapping  
            ESRI.ArcGIS.Geodatabase.IEnumNameMapping enumNameMapping = null;

            bool hasConflicts = geoDBDataTransferCls.GenerateNameMapping(enumName, name, out enumNameMapping);

            // Create Exporter and export the dataset in binary format not compressed and include the metadata
            ESRI.ArcGIS.GeoDatabaseDistributed.IGdbXmlExport gdbXmlExportCls = new ESRI.ArcGIS.GeoDatabaseDistributed.GdbExporter();
            gdbXmlExportCls.ExportDatasets(enumNameMapping, outXmlFile, true, false, true);
        }
        #endregion


[Visual Basic .NET, C++]
No example is available for Visual Basic .NET or C++. To view a Visual Basic 6.0 or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.