Avatar of tommyboy115
tommyboy115
Flag for United States of America

asked on 

XML String Created with VBA has Random Line Breaks

Hello,

I'm creating a fairly long XML string with VBA and it's inserting random line breaks, which are breaking the XML if they end up in the middle of a tag.  One reason the strings are so long is that I'm converting a PDF to Base64 as part of it.  I've tried using a replace function to remove the Chr$(13) and Chr$(10) characters, but that doesn't seem to be doing it.

Here's a shorter example, but with the same problem at the end:

<?xml version="1.0"?><OutboundRequest><AccessControl><UserName>#####</UserName><Password>####</Password></AccessControl><Transmission><TransmissionControl><TransmissionID>TMH</TransmissionID><Resolution>STANDARD</Resolution><Priority>NORMAL</Priority><SelfBusy>ENABLE</SelfBusy><FaxHeader>@DATE1   @TIME3   ANYWHERE (555) 124-1215   Page%P of @TPAGES</FaxHeader></TransmissionControl><DispositionControl><DispositionURL></DispositionURL><DispositionLevel>BOTH</DispositionLevel><DispositionMethod>EMAIL</DispositionMethod><DispositionEmails><DispositionEmail><DispositionRecipient>JANE DOE</DispositionRecipient><DispositionAddress>JANEDOE@GOOGLE.COM</DispositionAddress></DispositionEmail></DispositionEmails></DispositionControl><Recipients><Recipient><RecipientName>JANE DOE</RecipientName><RecipientCompany></RecipientCompany><RecipientFax>0000000000</RecipientFax></Recipient></Recipients><Files><File><FileContents></FileContents><FileType>pdf</FileType></File></Files></Transmission></OutboundReq
uest>

The last tag is broken and that causes the subsequent HTTP post to fail.  When looking at it in Notepad ++, it's a CRLF in there.  I'm not sure why I can't remove it.

There are the functions I'm using to remove them, with no luck:

Function RemoveReturns(varName As Variant) As Variant

    If (IsNull(varName)) Then
       
        Exit Function
   
    Else
   
    Dim i As Integer, varHold As Variant
   
      For i = 1 To Trim(Len(varName))
        If Mid(varName, i, 1) <> Chr$(13) Then
         varHold = varHold & Mid(varName, i, 1)
         Else
         varHold = varHold & "  "
        End If
     Next i
             
    RemoveReturns = varHold
   
    End If
   
End Function

Function RemoveLFs(varName As Variant) As Variant

    If (IsNull(varName)) Then
       
        Exit Function
   
    Else
   
    Dim i As Integer, varHold As Variant
   
      For i = 1 To Trim(Len(varName))
        If Mid(varName, i, 1) <> Chr$(10) Then
         varHold = varHold & Mid(varName, i, 1)
         Else
         varHold = varHold & "  "
        End If
     Next i
             
    RemoveLFs = varHold
   
    End If
   
End Function

Any help is appreciated!
Microsoft AccessVBAXML

Avatar of undefined
Last Comment
tommyboy115

8/22/2022 - Mon