By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,455 Members | 1,430 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,455 IT Pros & Developers. It's quick & easy.

Invalid character returned when reading UTF-8 XML

P: n/a
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
Share this Question
Share on Google+
7 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.