473,395 Members | 1,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Invalid character returned when reading UTF-8 XML

My XML is using encoding UTF-8 and its content contains Chinese character.
When debug the following codes:

string strXmlFile = "xml.xml";
XmlDocument objXml = new XmlDocument();

objXml.Load(strXmlFile);

It returns "Invalid character in the given encoding" and point to
objXml.Load(strXmlFile);.

How can I solve this matter?
There are many examples found to show UTF-8 string but load UTF-8 XML.

Jun 30 '08 #1
7 6811
Elliot <el************@hotmail.co.ukwrote:
My XML is using encoding UTF-8 and its content contains Chinese character.
When debug the following codes:

string strXmlFile = "xml.xml";
XmlDocument objXml = new XmlDocument();

objXml.Load(strXmlFile);

It returns "Invalid character in the given encoding" and point to
objXml.Load(strXmlFile);.

How can I solve this matter?
There are many examples found to show UTF-8 string but load UTF-8 XML.
Sounds like your XML is actually invalid. Can you shrink it down to a
very small amount (just an element with some text in should be enough)
which still shows the problem, then base64 encode it and post it here?

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon_skeet
C# in Depth: http://csharpindepth.com
Jun 30 '08 #2
Elliot wrote:
My XML is using encoding UTF-8 and its content contains Chinese character.
When debug the following codes:

string strXmlFile = "xml.xml";
XmlDocument objXml = new XmlDocument();

objXml.Load(strXmlFile);

It returns "Invalid character in the given encoding" and point to
objXml.Load(strXmlFile);.

How can I solve this matter?
Chance are good that you have encoding="UTF-8" in the XML file,
but that the content is actually in another encoding like
ISO-8859-1.

Arne
Jun 30 '08 #3
Solved by changing encoding to BIG5.
"Elliot" <el************@hotmail.co.ukwrote in message
news:2E**********************************@microsof t.com...
My XML is using encoding UTF-8 and its content contains Chinese character.
When debug the following codes:

string strXmlFile = "xml.xml";
XmlDocument objXml = new XmlDocument();

objXml.Load(strXmlFile);

It returns "Invalid character in the given encoding" and point to
objXml.Load(strXmlFile);.

How can I solve this matter?
There are many examples found to show UTF-8 string but load UTF-8 XML.
Jul 1 '08 #4
Elliot skrev:
Solved by changing encoding to BIG5.
I would call that a workaround for a XML file not containing UTF-8 when
it's declaration tells that it would. It's not a fix.

--
Bj?rn Brox
Jul 1 '08 #5
Elliot wrote:
"Elliot" <el************@hotmail.co.ukwrote in message
news:2E**********************************@microsof t.com...
>My XML is using encoding UTF-8 and its content contains Chinese
character.
When debug the following codes:

string strXmlFile = "xml.xml";
XmlDocument objXml = new XmlDocument();

objXml.Load(strXmlFile);

It returns "Invalid character in the given encoding" and point to
objXml.Load(strXmlFile);.

How can I solve this matter?
There are many examples found to show UTF-8 string but load UTF-8 XML.
Solved by changing encoding to BIG5.
Which means that the file content was not UTF-8.

Arne
Jul 2 '08 #6
Bj?rn Brox wrote:
Elliot skrev:
>Solved by changing encoding to BIG5.
I would call that a workaround for a XML file not containing UTF-8 when
it's declaration tells that it would. It's not a fix.
Isn't it a fix to change the declaration to match the actual content ??

Arne
Jul 2 '08 #7
Arne Vajhøj skrev:
Bj?rn Brox wrote:
>Elliot skrev:
>>Solved by changing encoding to BIG5.
I would call that a workaround for a XML file not containing UTF-8 when
it's declaration tells that it would. It's not a fix.

Isn't it a fix to change the declaration to match the actual content ??
It's a fix if you change this in the program producing the XML file.

It's a workaround if you manually edit the file afterwards or force
loading it as BIG5.

Anyhow, Elliot did not give enough details to make a conclusion, but my
first impression was that the fix was not done at the server-side.

--
Bjørn Brox
Jul 2 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: WindAndWaves | last post by:
Hi Folk Here I am writing my first php / mysql site, almost ready, and now this... charactersets.... The encoding that I use on my webpage is: <META HTTP-EQUIV="content-type"...
6
by: Marco Montel | last post by:
I have two applications that should comunicate through an xml file. This xml will contain a CDATA section with a digital signature. The problem is that the digital signature is composed of...
9
by: Safalra | last post by:
The idea here is relatively simple: a java program (I'm using JDK1.4 if that makes a difference) that loads an HTML file, removes invalid characters (or replaces them in the case of common ones...
3
by: Todd | last post by:
Our ASP.NET (C#) application accepts form entry and saves inputed data in XML. We are finding that users are sometimes cutting and pasting special characters (from MS Word) into these forms....
2
by: Glen | last post by:
I'm new to XML, so this is a newbie question. I'm reading in XML docs via a VB.NET application and extracting node data and I find that one of my blocks or lines has a copyright character in it....
0
by: Ben Holness | last post by:
Hi all, I have a system which allows users to enter a message on a (PHP) website. This message is then put into a (MySQL) Database. A perl script then picks up the message and creates an XML...
4
by: George | last post by:
Hi, I am puzzled by the following and seeking some assistance to help me understand what happened. I have very limited encoding knowledge. Our SAP system writes out a text file which includes...
2
by: David J Birnbaum | last post by:
Dear Python-list, I need to read a Unicode (utf-8) file that contains text like: I get my input and then process it with something like: When Python encounters the "\f" substring in an input...
14
by: Ioannis Vranos | last post by:
The following code does not work as expected: #include <wchar.h> #include <locale.h> #include <stdio.h> #include <stddef.h> int main() {
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.