473,387 Members | 1,534 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,387 software developers and data experts.

System.Xml.XmlException: hexadecimal value is an invalid character

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. The data is saved successfuly, but when the XML is
later read the following error is encountered depending on
the invalid character found:

This is a sample:
System.Xml.XmlException: '', hexadecimal value 0x1A, is
an invalid character.

I have ensured that the saved XML includes an encoding
declaration (<?xml version="1.0" encoding ='UTF-8'?>).
Changing the encoding format does not effect the error
message.

The XML parser installed is MSXML 4.0.

Is there any way to handle the reading of these
characters, or any way to ensure these characters are
converted into something readable at the time the values
are written to the XML object?

Any help is greatly appreciated.
Nov 12 '05 #1
3 22219
Todd wrote:
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. The data is saved successfuly, but when the XML is
later read the following error is encountered depending on
the invalid character found:


How do you save that data? Show us how do you create that XML.
It could be the problem with XmlTextWriter, which doesn't check unicode
characters that do not fit the specified encoding and hence can produce
non well-formed XML. See "Customized XML Writer Creation" article [1] in
msdn how to handle the issue.

[1]
ms-help://MS.MSDNQTR.2003JUL.1033/cpguide/html/cpconwritingxmlwithxmlwriter.htm
--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

Nov 12 '05 #2
-----Original Message-----
Todd wrote:
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. The data is saved successfuly, but when the XML is later read the following error is encountered depending on the invalid character found:
How do you save that data? Show us how do you create that

XML.It could be the problem with XmlTextWriter, which doesn't check unicodecharacters that do not fit the specified encoding and hence can producenon well-formed XML. See "Customized XML Writer Creation" article [1] inmsdn how to handle the issue.

[1]
ms- help://MS.MSDNQTR.2003JUL.1033/cpguide/html/cpconwritingxml
withxmlwriter.htm--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

.


This is how the XML is created:

protected void Application_Start(Object sender, EventArgs
e)
{
XmlDocument xml = new XmlDocument
();
StringBuilder sb = new
StringBuilder();
StringWriter sw = new StringWriter
(sb);
XmlTextWriter xmlText = new
XmlTextWriter(sw);
xml.LoadXml
(ConstantsXML.getInstance().GetValueFromKey
("ReportXmlTemplate"));
xml.WriteContentTo(xmlText);
Application["ReportXml"] =
sb.ToString();
}

Where the value for "ReportXmlTemplate" is:
&lt;?xml version='1.0' encoding='UTF-8'?
&gt;&lt;ReportXML&gt;&lt;/ReportXML&gt;
Nov 12 '05 #3
Hi Todd,

"Todd" <to*************@hotmail.com> wrote in message
news:00****************************@phx.gbl...
This is a sample:
System.Xml.XmlException: '', hexadecimal value 0x1A, is
an invalid character.


I'm not aware of anything that'll let you pick out these characters
from an instance and correct the problem. Always a tricky issue.
It's not clear to me that DOM Level 3 Validation will handle
this either, although I've just skimmed that.
(http://www.w3.org/TR/2003/CR-DOM-Level-3-Val-20030730/)
Your case is simpler since you say the encoding is under
your control. There aren't too many ranges that aren't allowed,
so perhaps you can just filter these out upstream.

From 2.2 of the rec "Characters":

[2] Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] |
[#x10000-#x10FFFF]

In particular (re your sample error), if you see
anything < #x20 that's not a tab, lf or cr convert it or remove it.

Regards,

-djm
Nov 12 '05 #4

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

Similar topics

1
by: Martin Honnen | last post by:
With both .NET 1.0 and 1.1 I have found the following strange behaviour where System.Xml.XmlDocument.LoadXml doesn't throw an error when parsing a text node with a character reference to an invalid...
5
by: Damon | last post by:
I'm getting '', hexadecimal value 0x02, is an invalid character when I'm deseralizing XML from a 3rd party XML gateway. How do I get rid of these hexadecimal values before I deserialize? Cheers...
0
by: Ramon de Klein | last post by:
I try to serialize an exception using the SoapFormatter, but this is a little bit problematic. The MethodInfo tag of the serialized exception contains &x00 characters (ASCII 0x00) in its serialized...
2
by: theonlyzahid | last post by:
Hi, I am getting his weired error when i open my webpage. Parser Error Message: '<', hexadecimal value 0x3C, is an invalid attribute character. Line 13, position 68. Source Error:
8
by: Vijay | last post by:
Hi , I am doing a small project in c. I have a Hexadecimal file and want to convert into ascii value. (i.e., Hexadecimal to Ascii conversion from a file). Could anyone help me? Thanks in...
7
by: elliotng.ee | last post by:
I have a text file that contains a header 32-bit binary. For example, the text file could be: %%This is the input text %%test.txt Date: Tue Dec 26 14:03:35 2006...
5
by: Just D | last post by:
All, Any valuable idea about subj: "The '%' character, hexadecimal value 0x25" ? I tried to google, but nothing interesting was found. Is it IIS settings problem, user side problem or...
6
by: Andrea | last post by:
Hi, suppose that I have a string that is an hexadecimal number, in order to print this string I have to do: void print_hex(unsigned char *bs, unsigned int n){ int i; for (i=0;i<n;i++){...
0
by: danasegarane | last post by:
Hi all, I am using this code to retrive the Viewsource content of page(Page content will be showed in XML). It was working well. But now I face one problem , the XML contain any special...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.