We help IT Professionals succeed at work.
Get Started

XML String Created with VBA has Random Line Breaks

tommyboy115
tommyboy115 asked
on
215 Views
Last Modified: 2017-11-10
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!
Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 7 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE