Skip to content

Commit

Permalink
Add alternate XML format function for big files
Browse files Browse the repository at this point in the history
Large XML files may cause memory errors with XSLT operations. Adding an alternate approach to simply replace the leading tabs with two spaces. This should allow the add-in to export even extremely large table data files as formatted XML. #389, fixes #474
  • Loading branch information
joyfullservice committed Dec 12, 2023
1 parent 9bb017b commit 1c8ec58
Showing 1 changed file with 69 additions and 1 deletion.
70 changes: 69 additions & 1 deletion Version Control.accda.src/modules/clsSourceParser.cls
Original file line number Diff line number Diff line change
Expand Up @@ -940,8 +940,19 @@ Private Function SanitizeXML() As String

Perf.OperationEnd

' Check string length to determine which formatter to use.
' (XSLT does a better job, but may fail on large sets of data)
If Len(strXML) < 30000 Then
' Use XSLT to format the XML output.
this.strOutput = FormatXML(objXml)
Else
' For very large XML strings like exporting data from large tables,
' use an alternate simplified formatting function that avoids
' the memory errors than can occur with XSLT.
this.strOutput = FormatXML2(objXml.XML)
End If

' Save the output
this.strOutput = FormatXML(objXml)
SanitizeXML = this.strOutput

' Show stats if debug turned on.
Expand Down Expand Up @@ -1075,6 +1086,63 @@ Private Function FormatXML(objInput As MSXML2.DOMDocument60, _
End Function


'---------------------------------------------------------------------------------------
' Procedure : FormatXML2
' Author : Adam Waller
' Date : 12/12/2023
' Purpose : Alternate approach to formatting XML for use in large data sets where
' : the XSL transformation may encounter memory errors.
'---------------------------------------------------------------------------------------
'
Private Function FormatXML2(strInput As String) As String

Dim varLines As Variant
Dim varLine As Variant
Dim lngChar As Long

Perf.OperationStart "Format XML (alt)"

' Split file into lines
varLines = Split(strInput, vbCrLf)

With New clsConcat
.AppendOnAdd = vbCrLf

' Loop through lines
For Each varLine In varLines

' Reset position
lngChar = 1

' Loop through leading characters, watching for tabs.
Do While lngChar < Len(varLine)
' See if this is
Select Case AscW(Mid(varLine, lngChar, 1))
Case vbKeyTab ' 9
' Increment tab counter
lngChar = lngChar + 1
Case Else
' Some other character.
Exit Do
End Select
Loop

' Add line with any indent
.Add Space$((lngChar - 1) * 2), Mid(varLine, lngChar)

Next varLine

' Remove trailing vbCrLf and return result
.Remove 2
FormatXML2 = .GetStr

End With

Perf.OperationEnd

End Function


'---------------------------------------------------------------------------------------
' Procedure : Class_Terminate
' Author : Adam Waller
Expand Down

0 comments on commit 1c8ec58

Please sign in to comment.