Write XML to a file using Visual Basic

webmasterbeta

New Member
' Open the file to write XML data to itOpen strFileName For Output As intFileNum' Create a string full of XML to output to the XML filePrint #intFileNum, "<WDObjects>" & vbCrLf & Chr(9) & "<WDDatabase>" &vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & "<Description>Millennia</Description>"& vbCrLfGetDatabaseIDPrint #intFileNum, Chr(9) & Chr(9) & "<ID>" & strDatabaseID & "</ID>"& vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & "<Server>Dan</Server>" & vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & "<WDDatabaseRights>" & vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & Chr(9) & "<AccessDatabase>True</AccessDatabase>"& vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & Chr(9) & "<AddDocuments>True</AddDocuments>"& vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & Chr(9) & "<AnnotateDocuments>True</AnnotateDocuments>"& vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & Chr(9) & "<CheckOutDocuments>True</CheckOutDocuments>"& vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & "</WDDatabaseRights>" & vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & "<WDCategory>" & vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & Chr(9) & "<AllowBlank>True</AllowBlank>"& vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & Chr(9) & "<ValueType>3</ValueType>"& vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & Chr(9) & "<ID>Tab</ID>" & vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & Chr(9) & "<Length>3</Length>" &vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & "</WDCategory>" & vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & "<WDCategory>" & vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & Chr(9) & "<AllowBlank>True</AllowBlank>"& vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & Chr(9) & "<ValueType>3</ValueType>"& vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & Chr(9) & "<ID>MGDocumentNumber</ID>"& vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & Chr(9) & "<Length>3</Length>" &vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & "</WDCategory>" & vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & "<WDCategory>" & vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & Chr(9) & "<AllowBlank>True</AllowBlank>"& vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & Chr(9) & "<ValueType>3</ValueType>"& vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & Chr(9) & "<ID>TenantNumber</ID>"& vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & Chr(9) & "<Length>3</Length>" &vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & "</WDCategory>" & vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & "<WDCategory>" & vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & Chr(9) & "<AllowBlank>True</AllowBlank>"& vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & Chr(9) & "<ValueType>200</ValueType>"& vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & Chr(9) & "<ID>PropertyName</ID>"& vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & Chr(9) & "<Length>255</Length>"& vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & "</WDCategory>" & vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & "<WDCategory>" & vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & Chr(9) & "<AllowBlank>True</AllowBlank>"& vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & Chr(9) & "<ValueType>200</ValueType>"& vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & Chr(9) & "<ID>ClosingBinderName</ID>"& vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & Chr(9) & "<Length>255</Length>"& vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & "</WDCategory>" & vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & "<WDFolder>" & vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & Chr(9) & "<Description>" & ParseSpecialChars(adoFldPropertyName.Value)& "</Description>" & vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & Chr(9) & "<WDFolder>" & vbCrLf' Loop through the records within the DocTypeTableDo While Not adoDocTypeTableRS.EOF' Compare two values to see if they coincide with one another' Does the name in this table match the name in that table?If adoFldDocTypeName.Value = adoFldDocumentDocTypeName.Value ThenPrint #intFileNum, Chr(9) & Chr(9) & Chr(9) & Chr(9) & "<Description>"& ParseSpecialChars(adoFldDocTypeName.Value) & "</Description>" & vbCrLfEnd If' Move to the next record within the DocTypeTableadoDocTypeTableRS.MoveNextLoop' Move to the first record within the DocTypeTableadoDocTypeTableRS.MoveFirstPrint #intFileNum, Chr(9) & Chr(9) & Chr(9) & Chr(9) & "<WDFolder>" &vbCrLf' Loop through the records within the ClosingBinderTableDo While Not adoClosingBinderTableRS.EOF' Compare two values to see if they coincide with one another' Does the number in this table match the number in that table?If adoFldClosingBinderNumber.Value = adoFldDocumentClosingBinderNumber.ValueThenPrint #intFileNum, Chr(9) & Chr(9) & Chr(9) & Chr(9) & Chr(9)& "<Description>" & ParseSpecialChars(adoFldClosingBinderName.Value) & "</Description>"& vbCrLfEnd If' Move to the next record within the ClosingBinderTableadoClosingBinderTableRS.MoveNextLoop' Move to the first record within the ClosingBinderTableadoClosingBinderTableRS.MoveFirst' Check to see if the user supplied the' program with a path to the pdf documentsIf PathToPDFDocuments <> "" Then' Obtain a user specified value' of the path to the pdf documentsGetPDFPathElse' To Do: Write some error handling stuffEnd If' Loop through each record within the DocumentTableDo While Not adoDocumentTableRS.EOFadoDocumentTableRS.RecordCountPrint #intFileNum, Chr(9) & Chr(9) & Chr(9) & Chr(9) & Chr(9) & "<WDDocument>"& vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & Chr(9) & Chr(9) & Chr(9) & Chr(9)& "<Title>" & ParseTitleChars(adoFldDocumentName.Value) & "</Title>" & vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & Chr(9) & Chr(9) & Chr(9) & Chr(9)& "<FilePath>" & strPDFPath & adoFldDocumentNumber.Value & ".pdf" & "</FilePath>"& vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & Chr(9) & Chr(9) & Chr(9) & Chr(9)& "<MimeType>" & "application/pdf" & "</MimeType>" & vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & Chr(9) & Chr(9) & Chr(9) & Chr(9)& "<ID>" & adoFldDocumentTab.Value & "</ID>" & vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & Chr(9) & Chr(9) & Chr(9) & Chr(9)& "<WDCategory>" & vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & Chr(9) & Chr(9) & Chr(9) & Chr(9)& Chr(9) & "<Tab>" & adoFldDocumentTab.Value & "</Tab>" & vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & Chr(9) & Chr(9) & Chr(9) & Chr(9)& Chr(9) & "<MGDocumentNumber>" & adoFldDocumentNumber.Value & "</MGDocumentNumber>"& vbCrLf' Check to see if the DocumentPropertyNumber is not equal to0If adoFldDocumentPropertyNumber <> 0 ThenPrint #intFileNum, Chr(9) & Chr(9) & Chr(9) & Chr(9) & Chr(9)& Chr(9) & Chr(9) & "<PropertyName>" & ParseSpecialChars(adoFldPropertyName.Value)& "</PropertyName>" & vbCrLfEnd If' Check to see if the DocumentTenantNumber is not equal to 0If adoFldDocumentTenantNumber <> 0 ThenPrint #intFileNum, Chr(9) & Chr(9) & Chr(9) & Chr(9) & Chr(9)& Chr(9) & Chr(9) & "<TenantName>" & ParseSpecialChars(adoFldTenantName.Value)& "</TenantName>" & vbCrLfEnd If' Check to see if the DocumentClosingBinderNumber is not equalto 0If adoFldDocumentClosingBinderNumber <> 0 ThenPrint #intFileNum, Chr(9) & Chr(9) & Chr(9) & Chr(9) & Chr(9)& Chr(9) & Chr(9) & "<ClosingBinderName>" & ParseSpecialChars(adoFldClosingBinderName.Value)& "</ClosingBinderName>" & vbCrLfEnd IfPrint #intFileNum, Chr(9) & Chr(9) & Chr(9) & Chr(9) & Chr(9) & Chr(9)& "</WDCategory>" & vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & Chr(9) & Chr(9) & Chr(9) & "</WDDocument>"& vbCrLf' Move to the next record with the DocumentTableadoDocumentTableRS.MoveNextLoopPrint #intFileNum, Chr(9) & Chr(9) & Chr(9) & Chr(9) & "</WDFolder>"& vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & Chr(9) & "</WDFolder>" & vbCrLfPrint #intFileNum, Chr(9) & Chr(9) & "</WDFolder>" & vbCrLfPrint #intFileNum, Chr(9) & "</WDDatabase>" & vbCrLf & "</WDObjects>"' Close the XML fileClose intFileNum
 
Back
Top