8

I need to export some of the feature classes to an xml file ("export xml workspace") quite often so I'd like to automate the process. I've found an example here how to export a feature dataset to an xml file. I haven't been able to modify the code so that it would export only the feature classes I want (for example only the ones that start with a letter 'A'). I also need to export the tables and relationshipclasses (schema only).

Is this possible at all? I know there is an interface IFeatureClassName, but I don't know how to use it in this case. Should this be done with arcpy instead?

I'm using ArcGIS 10.0 SP3.

2 Answers 2

6
+50

Instead of getting the dataset:

// Retrieve the first feature dataset from the workspace.
IEnumDatasetName enumDatasetName = workspace.get_DatasetNames
    (esriDatasetType.esriDTFeatureDataset);

You can get the feature class by:

IEnumDatasetName enumDatasetName = workspace.get_DatasetNames(esriDatasetType.esriDTFeatureClass);

See this thread:

Exporting/importing a geodatabase feature class to an XML file

UPDATE

You can get fc names within geodatabase/feature dataset using this code (solution in VB.NET):

Sub TestGetContents()

        Try
            Dim pGxApp As IGxApplication
            Dim Type As System.Type = System.Type.GetTypeFromCLSID(GetType(ESRI.ArcGIS.Framework.AppRefClass).GUID)
            pGxApp = TryCast(Activator.CreateInstance(Type), ESRI.ArcGIS.CatalogUI.IGxApplication)
            'select geodatabase in Catalog tree
            If Not TypeOf pGxApp.SelectedObject Is IGxDatabase Then
                Debug.Print("select a geodb first")
                Exit Sub
            End If
            Dim c As Collection
            c = GetContents(pGxApp.SelectedObject)
            Dim l As Long
            For l = 1 To c.Count
                Dim pName As IName
                pName = c.Item(l)
                If TypeOf pName Is IFeatureClassName Then
                    Dim pFC As IFeatureClass
                    pFC = pName.Open
                    MessageBox.Show(pFC.AliasName)

                ElseIf TypeOf pName Is IFeatureDatasetName Then
                    Dim pDSName As IDatasetName
                    pDSName = pName
                    MessageBox.Show(pDSName.Name)

                End If
            Next l
        Catch ex As Exception
            MessageBox.Show("Caught an unspecified error in the calling code: " & vbCrLf & ex.ToString)
        End Try

    End Sub


    Function GetContents(ByVal pGxDB As IGxDatabase) As Collection

        Try
            Dim c As New Collection
            Dim pEnumDSName As IEnumDatasetName
            pEnumDSName = pGxDB.Workspace.DatasetNames(esriDatasetType.esriDTAny)
            Dim pDSName As IDatasetName
            pDSName = pEnumDSName.Next
            Do Until pDSName Is Nothing
                If TypeOf pDSName Is IFeatureClassName Then
                    c.Add(pDSName)
                ElseIf TypeOf pDSName Is IFeatureDatasetName Then
                    c.Add(pDSName)
                    AddSubNames(pDSName, c)
                End If
                pDSName = pEnumDSName.Next
            Loop
            GetContents = c
        Catch ex As Exception
            MessageBox.Show("Caught an unspecified error in the calling code: " & vbCrLf & ex.ToString)
        End Try

    End Function

    Sub AddSubNames(ByVal pDSName1 As IDatasetName, ByVal c As Collection)
        Try
            Dim pEnumDSName As IEnumDatasetName
            pEnumDSName = pDSName1.SubsetNames
            pEnumDSName.Reset()
            Dim pDSName2 As IDatasetName
            pDSName2 = pEnumDSName.Next
            Do Until pDSName2 Is Nothing
                If TypeOf pDSName2 Is IFeatureClassName Then
                    c.Add(pDSName2)
                End If
                pDSName2 = pEnumDSName.Next
            Loop
        Catch ex As Exception
            MessageBox.Show("Caught an unspecified error in the calling code: " & vbCrLf & ex.ToString)
        End Try

    End Sub

Code referenced from this post:

ArcObjects - enumerating feature classes and datasets within a geodatabase

3
  • The example in the thread is pretty much the same I've already tried. I don't understand how do I filter the feature classes from the IEnumDatasetName object? The (IName)name.NameString always returns an empty string. I also get an exception (Exception from HRESULT: 0x80040220) from GenerateNameMapping with the current code example...
    – kor_
    Commented Jan 22, 2013 at 10:31
  • @kor_, See my updated answer.
    – artwork21
    Commented Jan 23, 2013 at 13:19
  • Ah, so I have to cast the IName to IFeatureClassName or IFeatureClass and then open it, and THEN I have the actual name. How messy is that!
    – kor_
    Commented Jan 25, 2013 at 12:12
4

If you are at 10.1, try using the Export XML Workspace Document (Data Management) geoprocessing tool.

I'm not sure exactly what it will do if you specify a feature class that participates in a relationship class, but I imagine it will include the relationship class and related object classes as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.