You are here: > ESRI Forums > arcgis desktop discussion forums > Thread Replies

ArcGIS Desktop Discussion Forums

ArcGIS Desktop - Geoprocessing Scripting (Python, JavaScript, VB) forum

Export XML Workspace Document   Ken Carrier Feb 11, 2008
Re: Export XML Workspace Document   Michael Knight Feb 11, 2008
Re: Export XML Workspace Document   Jan Teisinger Mar 11, 2008
Re: Export XML Workspace Document   Ken Carrier Mar 12, 2008
Re: Export XML Workspace Document   Jan Teisinger Mar 12, 2008
Re: Export XML Workspace Document   Ken Carrier Mar 12, 2008
Re: Export XML Workspace Document   Jan Teisinger Mar 12, 2008
Re: Export XML Workspace Document   Ryan Clark Sep 28, 2008
Re: Export XML Workspace Document   Jan Teisinger Sep 29, 2008
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Export XML Workspace Document 
Author Ken Carrier 
Date Feb 11, 2008 
Message I need to know how to export a featureclass to xml workspace document programmatically.

This particular feature is not available as something that can be used inside Model Builder.

Has anyone been successful in automating this process.

Our featureclass resides in an 9.2 ArcSDE Enterprise GeoDatabase, Oracle 10g R2, using Windows Server 2003. The latest service packs have been applied to Desktop and Server.

I will also need to know how to import this exported featureclass to a PGDB once done.

The reason I have to use an XML workspace document is because the featureclass is an annotation fc and anytime we try exporting using right-click export, it exports the text as polygons, which is no good.

Any help would be greatly appreciated! 
  Ken Carrier
GIS Specialist
Montgomery County Ohio Water Services
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Export XML Workspace Document 
Author Michael Knight 
Date Feb 11, 2008 
Message You can do this with ArcObjects. If you want to do this inside of model builder you would have to create your own geoprocessing tool. Take a look at these interfaces:

http://edndoc.esri.com/arcobjects/9.2/ComponentHelp/esriGeoDatabaseDistributed/IGdbXmlImport.htm

http://edndoc.esri.com/arcobjects/9.2/ComponentHelp/esriGeoDatabaseDistributed/IGdbXmlExport.htm

And this developer help topic:
http://edndoc.esri.com/arcobjects/9.2/NET/e7d06ae9-a6d1-4248-a7a3-9d5f375f088c.htm 
  Michael Knight
GIS Solutions Architect
Contract Land Staff, LLC
Stafford, Texas

http://www.contractlandstaff.com

 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Export XML Workspace Document 
Author Jan Teisinger 
Date Mar 11, 2008 
Message Shame on ESRI for not including this as a GP tool. I have written this simple VB.NET app as a command line utility that performs the XML export and import.
It lets you pass parameters from the command line.

How to use this code:
Create new VB.NET project as Console Application, call it XMLExportImport.exe (for example) and paste in the code (ensure all ESRI.ArcGIS references are set).
It's using the ZIP xml export format.

Arguments:
XMLExportImport.exe EXPORTTOXML c:\temp\MyDB.mdb c:\temp\MyDB.ZIP
XMLExportImport.exe IMPORTFROMXML c:\temp\MyDB.mdb c:\temp\MyDB.ZIP

XMLExportImport.exe EXPORTTOXMLSDE MyServerName;sde:sqlserver:MyServerName\sqlexpress;MyDBName;DBO.DEFAULT c:\temp\MyDBName.zip
XMLExportImport.exe IMPORTFROMXMLSDE MyServerName;sde:sqlserver:MyServerName\sqlexpress;MyDBName;DBO.DEFAULT c:\temp\MyDBName.zip
(for SDE the connection args are semicolon separated. It's using direct connect for PSDE with OSA authentication, it would probably need to be changed for ESDE)

Understandably, if this was a GP tool, it would be 2-3 lines of code in Python (in AO it's over 100 lines code, but probably would be less for savvy AO programmers). Lets hope ESRI includes this as a GP tool for Python in the next release of ArcGIS, considering the export/import functions are the only way how to transfer schemas between DBs.

jan 
 
'*************************************************
'Export or Import XML from SDE or Access Database
'Written by Jan Teisinger (MGP Inc.)
'2008/03/11
'*************************************************
Imports ESRI.ArcGIS.Geodatabase
Imports ESRI.ArcGIS.DataSourcesGDB
Imports ESRI.ArcGIS.GeoDatabaseDistributed
Imports ESRI.ArcGIS.esriSystem
Imports System.Environment
Imports System.IO.Path

Module AOResourceTool
    Sub Main()
        Dim arguments = System.Environment.GetCommandLineArgs()
        Dim a = arguments
        If arguments.length > 1 Then
            If UCase(arguments(1)) = "EXPORTTOXML" Then
                Console.WriteLine("Exporting database to XML...")
                ExportWS(arguments(2), arguments(3))
            ElseIf UCase(arguments(1)) = "IMPORTFROMXML" Then
                Console.WriteLine("Import XML to database...")
                ImportWS(arguments(2), arguments(3))
            ElseIf UCase(arguments(1)) = "EXPORTTOXMLSDE" Then
                Console.WriteLine("Exporting SDE database to XML...")
                ExportWSSDE(arguments(2), arguments(3))
            ElseIf UCase(arguments(1)) = "IMPORTFROMXMLSDE" Then
                Console.WriteLine("Import XML to SDE database...")
                ImportWSSDE(arguments(2), arguments(3))
            End If
        End If
    End Sub
    Private Sub ExportWS(ByVal db As String, ByVal XmlFile As String)
        'EXPORTS DATABASE DATA TO XML FILE (ZIP)
        Dim pAO As IAoInitialize
        pAO = New AoInitialize 'AOInitialize has methods and properties that will allow you initialize licenses 
        pAO.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcInfo) 'Initialize your application with ArcInfo license 
        'create the WS
        Dim pWSF As IWorkspaceFactory
        pWSF = New AccessWorkspaceFactory
        Console.WriteLine(db)
        '*** Open PGDB ***
        Dim pWS As IWorkspace
        pWS = pWSF.OpenFromFile(db, 0)
        '*** Create Exporter ***
        Dim pExporter As IGdbXmlExport
        pExporter = New GdbExporter
        '*** Export WS to XML in normalized format and not compressed ***
        pExporter.ExportWorkspace(pWS, XmlFile, True, True, True)

    End Sub


    Private Sub ExportWSSDE(ByVal db As String, ByVal XmlFile As String)
        'EXPORTS DATABASE DATA TO XML FILE (ZIP)
        Dim pAO As IAoInitialize
        pAO = New AoInitialize 'AOInitialize has methods and properties that will allow you initialize licenses 
        pAO.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcInfo) 'Initialize your application with ArcInfo license 
        'create the WS
        Dim pSdeWorkspaceFactory As IWorkspaceFactory
        Dim pSdeWorkspace As IWorkspace
        Dim pConnectionProperties As IPropertySet
        'Split the connection arguments to list
        Dim pConnectionArray As String()
        pConnectionArray = db.Split(";")
        pConnectionProperties = New PropertySet
        With pConnectionProperties
            .SetProperty("SERVER", pConnectionArray(0)) 'MyServerName
            .SetProperty("INSTANCE", pConnectionArray(1)) '"sde:sqlserver:MyServerName\sqlexpress"
            .SetProperty("DATABASE", pConnectionArray(2)) 'DBNAME
            .SetProperty("Authentication_mode", "OSA")
            .SetProperty("VERSION", pConnectionArray(3)) 'DBO.DEFAULT
        End With
        '*** Open SDE ***
        pSdeWorkspaceFactory = New SdeWorkspaceFactory
        pSdeWorkspace = pSdeWorkspaceFactory.Open(pConnectionProperties, 0)
        '*** Create Exporter ***
        Dim pExporter As IGdbXmlExport
        pExporter = New GdbExporter
        '*** Export WS to XML in normalized format and not compressed ***
        pExporter.ExportWorkspace(pSdeWorkspace, XmlFile, True, True, True)

    End Sub

    Private Sub ImportWSSDE(ByVal db As String, ByVal XmlFile As String)
        'IMPORTS XML (ZIP) DATA TO DATABASE
        Dim pAO As IAoInitialize
        pAO = New AoInitialize 'AOInitialize has methods and properties that will allow you initialize licenses 
        pAO.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcInfo) 'Initialize your application with ArcInfo license
        Dim pSdeWorkspaceFactory As IWorkspaceFactory
        Dim pSdeWorkspace As IWorkspace
        Dim pConnectionProperties As IPropertySet
        'Split the connection arguments to list
        Dim pConnectionArray As String()
        pConnectionArray = db.Split(";")
        pConnectionProperties = New PropertySet
        With pConnectionProperties
            .SetProperty("SERVER", pConnectionArray(0)) 'MyServerName
            .SetProperty("INSTANCE", pConnectionArray(1)) 'sde:sqlserver:MyServerName\sqlexpress
            .SetProperty("DATABASE", pConnectionArray(2)) 'DBNAME
            .SetProperty("Authentication_mode", "OSA")
            .SetProperty("VERSION", pConnectionArray(3)) 'DBO.DEFAULT
        End With
        '*** Open SDE ***
        pSdeWorkspaceFactory = New SdeWorkspaceFactory
        pSdeWorkspace = pSdeWorkspaceFactory.Open(pConnectionProperties, 0)
        '*** Create Importer ***
        Dim pImporter As IGdbXmlImport
        pImporter = New GdbImporter
        Dim pEnumName As IEnumNameMapping
        '*** Read schema section from the xml file ****
        pImporter.GenerateNameMapping(XmlFile, pSdeWorkspace, pEnumName)
        '*** Create the schema and load the data ***
        pImporter.ImportWorkspace(XmlFile, pEnumName, pSdeWorkspace, False)
    End Sub

    Private Sub ImportWS(ByVal db As String, ByVal XmlFile As String)
        'IMPORTS XML (ZIP) DATA TO DATABASE
        Dim pAO As IAoInitialize
        pAO = New AoInitialize 'AOInitialize has methods and properties that will allow you initialize licenses 
        pAO.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcInfo) 'Initialize your application with ArcInfo license
        Dim pWSF As IWorkspaceFactory
        pWSF = New AccessWorkspaceFactory
        '*** Create new GDB ***
        Dim pWSN As IWorkspaceName
        pWSN = pWSF.Create(System.IO.Path.GetDirectoryName(db), System.IO.Path.GetFileName(db), Nothing, 0)
        Dim pName As IName
        pName = pWSN
        '*** Open PGDB ***
        Dim pWS As IWorkspace
        pWS = pName.Open
        '*** Create Importer ***
        Dim pImporter As IGdbXmlImport
        pImporter = New GdbImporter
        Dim pEnumName As IEnumNameMapping
        '*** Read schema section from the xml file ****
        pImporter.GenerateNameMapping(XmlFile, pWS, pEnumName)
        '*** Create the schema and load the data ***
        pImporter.ImportWorkspace(XmlFile, pEnumName, pWS, False)
    End Sub
End Module

 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Export XML Workspace Document 
Author Ken Carrier 
Date Mar 12, 2008 
Message Is there any way to put this on a button click?

I am running Oracle 10g r2, SDE 9.2, VS 2005.

In your code I see a reference to SQL Server, what do I need to do to make this work with my setup? Also I would like to be able to have seperate button clicks one for export and one for import.

Essentially two export buttons one to export from SDE and one to export from PGDB and the same setup for import. What I did not see is where you specified which featureclass you were wanting to export from SDE. Where in the code would you specify which featureclass you are wanting to export to XML? I would like to be able to hardcode the names of the featureclasses. Thanks for the code it is helping me to understand the structure a little better but I still think I may need some help putting this all together. Any help would be greatly appreciated! 
  Ken Carrier
GIS Specialist
Montgomery County Ohio Water Services
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Export XML Workspace Document 
Author Jan Teisinger 
Date Mar 12, 2008 
Message The objective of this tool is to run from the command line, so that it can be used either via Python or simple batch file.
What you are asking is for is a simple VBA procedure in ArcMap, that can be done fairly simply, i would think.
See the example code below. Alter the other Private Subs() in my previous code in the same way (change Private to Public for VBA and move args to body from the function args and declare them). Might be harder for SDE since i am parsing out the connection string via Python for the command line args, not sure how that would be done in VB.

You should then be able to copy paste this into the VBA editor and run it via Macro.

I think you might be able to just drag and drop the macro from the Customize-->Commands-->[Macro] section to ArcMap.

Hope this helps,
Jan 
 
Public Sub ExportWS()
    	dim db as String
    	dim XmlFile as String
    	'*** HARDCODE DB SOURCES HERE
    	db = "C:\temp\MyAccessBD.MDB"
    	XmlFile = "c:\temp\MyOutputXMLFile.ZIP"
    	'***
        'EXPORTS DATABASE DATA TO XML FILE (ZIP)
        Dim pAO As IAoInitialize
        pAO = New AoInitialize 'AOInitialize has methods and properties that will allow you initialize licenses 
        pAO.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcInfo) 'Initialize your application with ArcInfo license 
        'create the WS
        Dim pWSF As IWorkspaceFactory
        pWSF = New AccessWorkspaceFactory
        Console.WriteLine(db)
        '*** Open PGDB ***
        Dim pWS As IWorkspace
        pWS = pWSF.OpenFromFile(db, 0)
        '*** Create Exporter ***
        Dim pExporter As IGdbXmlExport
        pExporter = New GdbExporter
        '*** Export WS to XML in normalized format and not compressed ***
        pExporter.ExportWorkspace(pWS, XmlFile, True, True, True)

    End Sub
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Export XML Workspace Document 
Author Ken Carrier 
Date Mar 12, 2008 
Message This is great! I understand VBA fairly well. I am trying to create a standalone exe rather than use ArcMap is it possible to convert what you have in VBA to VB.NET? 
  Ken Carrier
GIS Specialist
Montgomery County Ohio Water Services
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Export XML Workspace Document 
Author Jan Teisinger 
Date Mar 12, 2008 
Message The code i have provided in my first post is a full blown VB.NET console application that runs from the command line as EXE, so it can be reused in other .NET projects.

If you want to build a GUI, you would just take out the Module class and the Main() function and then paste the Private functions into a new windows app project in VS.
perhaps you might be able to rewrite the Main() def into two OnClick() functions.
I hardly ever write .NET GUI applications, i write mainly in Python, so not sure about the details how to convert this to GUI.
Hope this helps, let me know if you have any more questions. Good luck !
jan

 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Export XML Workspace Document 
Author Ryan Clark 
Date Sep 28, 2008 
Message Any ideas about what it would take if I wanted to export some subset of my data in an XML workspace document? For example, I would like to use a Query to filter the records exported from a specific featureclass. It looks to me like the IGdbXmlExport methods only exports whole objectclasses or databases. Would I have to move the data I'm interested in to a scratch database and export the XML for that entire database?

Thanks,
Ryan 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Export XML Workspace Document 
Author Jan Teisinger 
Date Sep 29, 2008 
Message i am afraid moving data to scratch WS may be your only option, but i am unfamiliar with the A/O functions for exporting the XML Recordset. If you use SDE(entprs), you can create views from command line and then export the view to the XML recordset.

Have you tried GDB Designer ? that tool has superior functionality to most stock A/O XML functions. it's great for transferring schemas around. Unfortunately there is no command line interface via GP. I use it to transfer schemas to new DBs and then use gp.append(), which takes layers/views with filters.