Adding the file information to the document was the easiest. All I needed was to add a couple attributes to my database element. A couple of simple calls…
XmlDocument.documentElement.setAttribute "name", Application.CurrentProject.Name XmlDocument.documentElement.setAttribute "type", Application.CurrentProject.ProjectType
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <database name="Example.mdb" type="2"> <properties /> </database>
Project properties
The project properties were not much more difficult. This was a simple matter of looping through all of the project’s properties and creating an XML element for each. The code to do this is very terse indeed:Dim Parent, Child, Property Set Parent = XmlDocument.createElement("properties") XmlDocument.documentElement.appendChild Parent For Each Property In Project.Properties Set Child = XmlDocument.createElement("property") Child.setAttribute "name", Property.Name Child.setAttribute "value", Property.Value Parent.appendChild Child Next
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <database name="Example.mdb" type="2"> <properties> <property name="AllowByPassKey" value="-1" /> <property name="AppVersion" value="1.0" /> </properties> </database>
Removing linked tables
This was another minor feat, but it was somewhat more complicated than the properties. The reason is that I export the tables at a different point than I was doing the properties. As it turns out, though, it was not that bad.Private Sub ExportLinkedTables(ByVal Tables, ByVal DatabasePath, ByVal OutputFilePath) Dim XmlDocument, XmlLinkedTables, XmlLink Dim Table, LinkPath, LocalName, SourceName Set XmlDocument = CreateObject("Msxml2.DomDocument.6.0") XmlDocument.load OutputFilePath Set XmlLinkedTables = XmlDocument.selectSingleNode("database/linked-tables") If XmlLinkedTables Is Nothing Then Set XmlLinkedTables = XmlDocument.createElement("linked-tables") XmlDocument.documentElement.appendChild XmlLinkedTables End If For Each Table In Tables If IsLinkedTable(Table) Then LocalName = Table.Name SourceName = Table.SourceTableName LinkPath = Mid(Table.Connect, 11) If InStr(LinkPath, DatabasePath) = 1 Then LinkPath = Replace(LinkPath, DatabasePath, "") LinkPath = FileSystem.BuildPath(".", LinkPath) End If Set XmlLink = XmlDocument.createElement("link") XmlLink.setAttribute "name", LocalName XmlLink.setAttribute "source", SourceName XmlLink.setAttribute "database", LinkPath XmlLinkedTables.appendChild XmlLink End If Next WriteXmlDocument XmlDocument, OutputFilePath Set XmlLink = Nothing Set XmlLinkedTables = Nothing Set XmlDocument = Nothing End Sub
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <database name="Example.mdb" type="2"> <properties> <property name="AllowByPassKey" value="-1" /> <property name="AppVersion" value="1.0" /> </properties> <linked-tables> <link name="Logs" source="Logs" database=".\Archives.mdb" /> <link name="Cache" source="Master" database="C:\Temp\Cache.mdb" /> <link name="Archive" source="Master" database=".\Archives.mdb" /> <link name="Master" source="Master" database=".\Data.mdb" /> </linked-tables> </database>
No comments:
Post a Comment