Export Automation Object Example
The following examples show how to use the Export object in Microsoft® Visual Basic®.
Exporting to a File
The following example shows how to export object instance data for two repository objects. You do not need to bracket an export within a transaction. To release the objects after the export concludes, set the objects to nothing.
dim oExp as new Export
dim oMyObj1 as RepositoryObject
dim oMyObj2 as RepositoryObject
dim oRep as new Repository
dim oRoot as RepositoryObject
set oRoot=oRep.Open "SERVER=MyServer;DATABASE=MyDB;UID=sa;PWD=MyPassword;"
set oMyObj1=oRep.Object(objid1)
set oMyObj2=oRep.Object(objid2)
oExp.add oMyObj1
oExp.add oMyObj2
oExp.Export "c:\temp\myXmlFile.xml", INDENTATION
Set oMyObj1=Nothing
Set oMyObj2=Nothing
Set oRoot=Nothing
Set oRep=Nothing
Set oExp=Nothing
Exporting Multiple Objects in a Relationship
In the following example, oMyObj1 is a collection object that relates multiple objects. The COLLECTION_CONTAINING flag, which is set on the collection object, makes exporting a relationship possible. This flag is set in the information model and does not appear in your export code. Another flag, ADDCONTAINING_BASE (you can also use ADDCONTAINING_MOSTDERIVED) does appear in your export code. This flag supports the selection of objects in a relationship for the export process. This flag depends on the COLLECTION_CONTAINING flag to enable the selection.
dim oExp as new Export
dim oMyObj1 as RepositoryObject
dim oRep as new Repository
dim oRoot as RepositoryObject
set oRoot=oRep.Open "SERVER=MyServer;DATABASE=MyDB;UID=sa;PWD=MyPassword;"
set oMyObj1=oRep.Object(objid1)
oExp.add oMyObj1, ADDCONTAINING_BASE
oExp.Export "c:\temp\myXmlFile.xml", INDENTATION
Set oMyObj1=Nothing
Set oRoot=Nothing
Set oRep=Nothing
Set oExp=Nothing
Exporting to a String
The following example shows how to export the same object instance data to a string stored in memory:
dim oExp as new Export
dim oMyObj1 as RepositoryObject
dim oMyObj2 as RepositoryObject
dim oRep as new Repository
dim oRoot as RepositoryObject
set oRoot=oRep.Open "SERVER=MyServer;DATABASE=MyDB;UID=sa;PWD=MyPassword;"
set oMyObj1=oRep.Object(objid1)
set oMyObj2=oRep.Object(objid2)
oExp.add oMyObj1
oExp.add oMyObj2
set sXMLStr=Export.GetXML, INDENTATION
Set oMyObj1=Nothing
Set oMyObj2=Nothing
Set oRoot=Nothing
Set oRep=Nothing
Set oExp=Nothing