Private Declare Function GetTempPath Lib "kernel32" _
Alias "GetTempPathA" (ByVal nBufferLength As Long, _
ByVal lpBuffer As String) As Long
Private Declare Function GetTempFileName Lib "kernel32" _
Alias "GetTempFileNameA" (ByVal lpszPath As String, _
ByVal lpPrefixString As String, ByVal wUnique As Long, _
ByVal lpTempFileName As String) As Long
Public Sub PrettyPrint()
'***************************************************************************
'Purpose: When nodes are added, they wind up on the same line. This does not
' affect how they are read by xml readers, but it does make them
' difficult to read in Word, etc. While this routine does not correct
' indenting, it does at least break up the run-on lines.
'Inputs: The newly-modified xml file
'Outputs: The newly-modified xml file reformatted
'***************************************************************************
Dim intInFile As Integer
Dim intOutFile As Integer
Dim strLine As String
Dim strOutputLine As String
Dim strTempFile As String
Dim bDone As Boolean
Dim intPos As Integer
On Error GoTo ErrorRoutine
strTempFile = CreateTempFile("xml")
intInFile = FreeFile
Open My_XML_File For Input As intInFile
intOutFile = FreeFile
Open strTempFile For Output As intOutFile
While Not EOF(intInFile)
Line Input #intInFile, strLine
bDone = False
Do Until bDone
intPos = InStr(1, strLine, "><")
If intPos = 0 Then
bDone = True
Print #intOutFile, strLine
Else
strOutputLine = Left$(strLine, intPos)
Print #intOutFile, strOutputLine
strLine = Right$(strLine, Len(strLine) - intPos)
End If
Loop
Wend
Close intInFile
Close intOutFile
FileCopy strTempFile, My_XML_File
Kill strTempFile
Exit Sub
ErrorRoutine:
' Your error-routine here
End Sub
Public Function CreateTempFile(strPrefix As String) As String
'***************************************************************************
'Purpose: Create a unique temporary file name
'Inputs: strPrefix - The prefix to be used as the first part of the temp
' file name. Note: only the first 3 characters get used.
'Outputs: The temp file name
'***************************************************************************
Dim strTmpPath As String * 512
Dim strTmpName As String * 576
Dim intRet As Long
intRet = GetTempPath(512, strTmpPath)
If (intRet > 0 And intRet < 512) Then
intRet = GetTempFileName(strTmpPath, strPrefix, 0, strTmpName)
If intRet <> 0 Then
CreateTempFile = Left$(strTmpName, _
InStr(strTmpName, vbNullChar) - 1)
End If
End If
End Function