troubleshooting Question

XML String Created with VBA has Random Line Breaks

Avatar of tommyboy115
tommyboy115Flag for United States of America asked on
Microsoft AccessVBAXML
7 Comments1 Solution220 ViewsLast Modified:
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!
ASKER CERTIFIED SOLUTION
tommyboy115

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros