473,372 Members | 1,007 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,372 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 6810
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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...

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.