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!
tommyboy115Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
what if you replace CRLF directly like this?

Function RemoveCRLFs(varName As Variant) As Variant
    RemoveCRLFs = Replace(varName, vbCrLf, "")
End Function

Open in new window

0
tommyboy115Author Commented:
That doesn't get rid of it either.
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
what if changing:
For i = 1 To Trim(Len(varName))

Open in new window


to

For i = 1 To Len(varName)

Open in new window


?
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
or try something like this:

Function RemoveCRLFs(varName As Variant) As Variant
    RemoveCRLFs = Replace(Replace(Replace(varName, vbCrLf, ""), Chr(10), ""), Chr(13), "")
End Function

Open in new window

1
tommyboy115Author Commented:
I ended up just adding line breaks where I DID want them, like right after each tag.  That didn't eliminate the random ones, but made it so they showed up in other spots that didn't matter.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
well, you got to debug your codes so that you know what are the "random ones"...

if this question is no longer important, pls go ahead and delete the question.
0
tommyboy115Author Commented:
I figured out a solution that worked for me since none of the other suggestions worked.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.