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:
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]
staticvoid 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);
}