How to import data or schema from a resulting XML document


Summary
The article shows how to use the IGdbXmlImport interface to import schema and data or schema from a resulting Extensible Markup Language (XML) document to a geodatabase using GdbImporter. This example allows you to create a function by passing in the workspace path, database, and XML file name into a new geodatabase.

In this topic


Importing data or schema from a resulting XML document

The following code creates a geodatabase (dbName) at the workspace path location (workspacePathname):
[Java]
// Create a new geodatabase (dbName) at the workspacePathname location
IWorkspaceFactory workspaceFactory = new AccessWorkspaceFactory();
IWorkspaceName workspaceName = workspaceFactory.create(workspacePathname, dbName,
    null, 0);
Open the database
The following code example opens the Access database:
[Java]
// Open the geodatabase
IName name = (IName)workspaceName;
IWorkspace workspace = new IWorkspaceProxy(name.open()); // Explicit Cast
Create a class
The following code example creates a GdbImporter class:
[Java]
IGdbXmlImport gdbXmlImport = new GdbImporter();
Read schema section from the XML file
The following code example reads the schema section from the XML file. The enumNameMapping is initialized to nothing, and its value is set "by ref" with a call to the GenerateNameMapping method:
[Java]
IEnumNameMapping[] enumNameMapping = new IEnumNameMapping[1];
gdbXmlImport.generateNameMapping(inXmlFile, workspace, enumNameMapping);
Import schema and load data
The following code example imports the workspace schema and loads the data by passing in the XML file (inXmlFile), enumNameMapping, workspace, and Boolean (schemaOnly).
The inXmlFile is a string that identifies the import XML file, where you must specify the file extension. For example, the inXmlFile can have the following extensions: foo.xml, foo.ZIP, or foo.Z.
If you set the schemaOnly property to true, the imported workspace contains the schema and not data. Otherwise, the imported workspace contains the schema and data. See the following code example:
[Java]
gdbXmlImport.ImportWorkspace(inXmlFile, enumNameMapping, workspace, false);
Use XML import workspace to import data or schema
The following code example is the complete function of how to use XML import workspace to import data or schema from a resulting XML document. To use the function, pass in the workspace path, database name, and input XML file:
[Java]
static void importFromXml(String workspacePathname, String dbName, String inXmlFile)
    throws Exception{
    // Create a new access database (dbName) at the workspacePathname location
    IWorkspaceFactory workspaceFactory = new AccessWorkspaceFactory();
    IWorkspaceName workspaceName = workspaceFactory.create(workspacePathname, dbName,
        null, 0);

    // Open the geodatabase
    IName name = (IName)workspaceName;
    IWorkspace workspace = new IWorkspaceProxy(name.open()); // Explicit Cast
    // Create a GdbImporter
    IGdbXmlImport gdbXmlImport = new GdbImporter();
    // Read schema section from the xml file
    // Note: enumNameMapping is initialized to Nothing and it's value is set 'by ref' with a call to the GenerateNameMapping method
    IEnumNameMapping[] enumNameMapping = new IEnumNameMapping[1];
    gdbXmlImport.generateNameMapping(inXmlFile, workspace, enumNameMapping);
    // Create the workspace schema and load the data
    gdbXmlImport.importWorkspace(inXmlFile, enumNameMapping[0], workspace, false);
}






Additional Requirements
  • If working in ArcSDE, an ArcEditor or greater license is required on ArcGIS Desktop and the Geodatabase Update extension is required on ArcGIS Engine.

Development licensingDeployment licensing
ArcGIS for Desktop StandardArcGIS for Desktop Standard
ArcGIS for Desktop AdvancedArcGIS for Desktop Advanced
Engine Developer KitEngine: Geodatabase Update