XML parsing error: An invalid character was found in text content

Hi

I have created a DLL that generates XML files but eventually (not always) at the moment of opening those files in IExplorer I got this error:

"An invalid character was found in text content."

Investigating a little bit more, I have found that this has something to do with the encoding so the file has this at the top of it:

<?xml version="1.0" encoding="UTF-8"?>

And, I have tried to save it as Unicode instead of ANSI but didn´t work:

            sUTF8 = StrConv(s, vbUnicode)
            fileStream.Write (sUTF8)
            fileStream.Close

Any ideas?

Regards
dimensionavAsked:
Who is Participating?
 
dimmergeekCommented:
What character was encountred at time of error?
0
 
dimensionavAuthor Commented:
it gives the following string after the error:

<cfdi:Concepto cantidad="78" unidad="PIEZA" noIdentificacion="NA" descripcion="MANTEL INDIVIDUAL 45X33 CMS MARIPOSAS" val...
0
Ultimate Tool Kit for Technology Solution Provider

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 now.

 
dimensionavAuthor Commented:
I have made a test

I put that string in excel and I got the same string from another different file saved in utf8 with notepad and even watching the same characters, excel gives FALSE to EQUAL formula, I have noticed that maybe the blank spaces are the problem.
0
 
dimmergeekCommented:
As you create the XML, can you substitute underscores for spaces then run your script and see if the error still happens?
0
 
aikimarkCommented:
since strings are already stored in unicode, why do you use StrConv()?  Is the s variable a byte array?
0
 
dimensionavAuthor Commented:
dimmergeek:
If I do that, the problem is still present

aikimark, I do this with the s String before converting it but it isn´t a byte array:

            Set fileStream = fso.OpenTextFile(sSourcefile, 1)
            s = fileStream.ReadAll
            ifrom = InStr(1, s, sOpeningMark, vbTextCompare) + Len(sClosingMark) - 1
            ito = InStr(1, s, sClosingMark, vbTextCompare)

            sToBeReplaced = Mid(s, ifrom, ito - ifrom)
            s = Replace(s, sToBeReplaced, sToReplace)
            fileStream.Close
0
 
aikimarkCommented:
but WHY do you do that conversion?  In other words, what problem does this solve or error prevent?
0
 
dimensionavAuthor Commented:
I need to convert the string to UTF8, maybe this is where I am making a mistake because you said that the string comes in Unicode already.

Maybe the point of this could be, how could I convert this string to UTF8 correctly.

Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.