[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2012-09-14
9
Medium Priority
?
2,587 Views
Last Modified: 2012-10-02
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
0
Comment
Question by:dimensionav
  • 4
  • 3
  • 2
9 Comments
 
LVL 7

Expert Comment

by:dimmergeek
ID: 38400015
What character was encountred at time of error?
0
 

Author Comment

by:dimensionav
ID: 38400041
it gives the following string after the error:

<cfdi:Concepto cantidad="78" unidad="PIEZA" noIdentificacion="NA" descripcion="MANTEL INDIVIDUAL 45X33 CMS MARIPOSAS" val...
0
 

Author Comment

by:dimensionav
ID: 38400069
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 7

Expert Comment

by:dimmergeek
ID: 38400120
As you create the XML, can you substitute underscores for spaces then run your script and see if the error still happens?
0
 
LVL 46

Expert Comment

by:aikimark
ID: 38400959
since strings are already stored in unicode, why do you use StrConv()?  Is the s variable a byte array?
0
 

Author Comment

by:dimensionav
ID: 38410375
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
 
LVL 46

Expert Comment

by:aikimark
ID: 38410408
but WHY do you do that conversion?  In other words, what problem does this solve or error prevent?
0
 

Author Comment

by:dimensionav
ID: 38410658
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
 
LVL 46

Accepted Solution

by:
aikimark earned 2000 total points
ID: 38410851
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month18 days, 12 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question