Attribute VB_Name = "FSG" Sub WriteXML() Attribute WriteXML.VB_ProcData.VB_Invoke_Func = "m\n14" 'Created: 2006 MAY 'Creator: Shane Walker, EIT ' Center for Research in Water Resources (CRWR) ' Environmental and Water Resources Engineering (EWRE) ' The University of Texas at Austin 'This application creates an XML geodatabase schema to be imported into an ESRI geodatabase using the Geodatabase Designer 2 toolbar. Dim fso As New FileSystemObject Dim ts As TextStream Dim filename As String Dim message As String Dim c_month, c_day, c_hour, c_second As String 'metadata: creation date components Dim n As Integer 'counter Dim stfield As String 'subtype field Dim stcode As String 'default subtype code 'XML file location and name filename = InputBox("Please input the XML path and filename.", "XML Filename", "C:\FSG_geodatabase_schema.xml") If filename = "" Then GoTo 9999 Set ts = fso.CreateTextFile(filename, True, True) 'Header ts.WriteLine "" ts.WriteLine "" ts.WriteLine "" 'Metadata ts.WriteLine " " If Len(month(Now)) = 1 Then c_month = "0" & month(Now) Else: c_month = month(Now) End If If Len(day(Now)) = 1 Then c_day = "0" & day(Now) Else: c_day = day(Now) End If If Len(hour(Now)) = 1 Then c_hour = "0" & hour(Now) Else: c_hour = hour(Now) End If If Len(Minute(Now)) = 1 Then c_minute = "0" & Minute(Now) Else: c_minute = Minute(Now) End If If Len(second(Now)) = 1 Then c_second = "0" & second(Now) Else: c_second = second(Now) End If ts.WriteLine " " ts.WriteLine " " ts.WriteLine " " ts.WriteLine " " ts.WriteLine " " ts.WriteLine " " 'Domains Worksheets("Domains").Activate Range("A4").Select Do Until Selection = "" ts.WriteLine " " ActiveCell.Offset(1, 1).Select Do Until Selection = "" ts.WriteLine " " ActiveCell.Offset(1, 0).Select Loop ts.WriteLine " " ActiveCell.Offset(1, -1).Select Loop 'Feature Datasets and Feature Classes Worksheets("FeatureClasses").Activate Range("A4").Select Do Until Selection = "" 'Loop through all feature datasets ts.WriteLine " " ts.WriteLine " " ActiveCell.Offset(1, 1).Select Do Until Selection = "" 'Loop through all feature classes within a feature dataset stfield = ActiveCell.Offset(0, 6) stcode = ActiveCell.Offset(0, 7) ts.WriteLine " " ts.WriteLine " " ts.WriteLine " " ts.WriteLine " " ts.WriteLine " " ts.WriteLine " " ts.WriteLine " " ActiveCell.Offset(3, 8).Select n = 0 'initialize counter Do Until Selection = "" 'Loop through all fields within a feature class n = n + 1 'Count the number of fields ts.WriteLine " " ActiveCell.Offset(1, 0).Select Loop 'Loop fields ts.WriteLine " " ActiveCell.Offset(-n, 7).Select For i = 1 To n 'Loop through base domains If Selection <> "" Then ts.WriteLine " " ActiveCell.Offset(1, 0).Select Next i 'Loop base domains ts.WriteLine " " ActiveCell.Offset(0, 1).Select If stfield <> "" Then Do Until Selection = "" 'Loop through all subtype codes and names ts.WriteLine " " ActiveCell.Offset(1, 2).Select Do Until Selection = "" 'Loop through all subtype-specific domains ts.WriteLine " " ActiveCell.Offset(1, 0).Select Loop 'Loop subtype-specific domains ts.WriteLine " " ActiveCell.Offset(0, -2).Select Loop 'Loop subtype codes and names ts.WriteLine " " ts.WriteLine " " ts.WriteLine " " End If ts.WriteLine " " ts.WriteLine " " ts.WriteLine " " ts.WriteLine " " ts.WriteLine " " ts.WriteLine " " ts.WriteLine " " ActiveCell.Offset(1, -16).Select Loop 'Loop feature classes ActiveCell.Offset(0, -1).Select ts.WriteLine " " Loop 'Loop feature datasets 'Object Classes Worksheets("ObjectClasses").Activate Range("A4").Select Do Until Selection = "" 'Loop through all object classes stfield = ActiveCell.Offset(0, 2) stcode = ActiveCell.Offset(0, 3) ts.WriteLine " " ts.WriteLine " " ActiveCell.Offset(2, 4).Select n = 0 'initialize counter Do Until Selection = "" 'Loop through all fields within a feature class n = n + 1 'Count the number of fields ts.WriteLine " " ActiveCell.Offset(1, 0).Select Loop 'Loop fields ts.WriteLine " " ActiveCell.Offset(-n, 7).Select For i = 1 To n 'Loop through base domains If Selection <> "" Then ts.WriteLine " " ActiveCell.Offset(1, 0).Select Next i 'Loop base domains ts.WriteLine " " ActiveCell.Offset(0, 1).Select If stfield <> "" Then Do Until Selection = "" 'Loop through all subtype codes and names ts.WriteLine " " ActiveCell.Offset(1, 2).Select Do Until Selection = "" 'Loop through all subtype-specific domains ts.WriteLine " " ActiveCell.Offset(1, 0).Select Loop 'Loop subtype-specific domains ts.WriteLine " " ActiveCell.Offset(0, -2).Select Loop 'Loop subtype codes and names ts.WriteLine " " ts.WriteLine " " ts.WriteLine " " End If ts.WriteLine " " ts.WriteLine " " ts.WriteLine " " ts.WriteLine " " ts.WriteLine " " ts.WriteLine " " ts.WriteLine " " ActiveCell.Offset(1, -12).Select Loop 'Loop object classes 'Relationships Worksheets("Relationships").Activate Range("A4").Select Do Until Selection = "" 'Loop through all relationships ts.WriteLine " " ts.WriteLine " " ts.WriteLine " " ts.WriteLine " " ts.WriteLine " " ActiveCell.Offset(1, 0).Select Loop 'Loop relationships 'Finish writing XML and close the XML file ts.Write "" ts.Close Set ts = Nothing Set fso = Nothing 9999 If filename = "" Then message = "USER CANCELLED" Else message = "XML Complete" End If MsgBox (message) End Sub