473,699 Members | 2,656 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

System.Xml.XmlE xception: 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.XmlE xception: '', 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 22351
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.2003 JUL.1033/cpguide/html/cpconwritingxml withxmlwriter.h tm
--
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.2003 JUL.1033/cpguide/html/cpconwritingxml
withxmlwriter.h tm--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

.


This is how the XML is created:

protected void Application_Sta rt(Object sender, EventArgs
e)
{
XmlDocument xml = new XmlDocument
();
StringBuilder sb = new
StringBuilder() ;
StringWriter sw = new StringWriter
(sb);
XmlTextWriter xmlText = new
XmlTextWriter(s w);
xml.LoadXml
(ConstantsXML.g etInstance().Ge tValueFromKey
("ReportXmlTemp late"));
xml.WriteConten tTo(xmlText);
Application["ReportXml"] =
sb.ToString();
}

Where the value for "ReportXmlTempl ate" is:
&lt;?xml version='1.0' encoding='UTF-8'?
&gt;&lt;ReportX ML&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.Xml Exception: '', 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
17130
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 characters like &#x1;. Using the CreateTextNode method I create a text node containing "\u0001a" (C# string literal notation). As far as I understand the DOM allows that and an implementation is not required to throw an error. When OuterXml is...
5
7909
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 Damon
0
1892
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 data. When the data is deserialized on the client side the SoapHttpClientProtocol.ReadResponse uses an XmlTextReader with Normalization switched on. In that case the &x00 character is not valid and results in the following XmlException: ...
2
12302
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
18651
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 adv.
7
19216
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 00000000000000001111111111111111 11111111111111111111111111111111 00000000000000000000000000000000 11111111111111110000000000000000
5
11651
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 whatever? We receive it regularly and I guess the problem is not in our source codes. Please help! Just D.
6
14552
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++){ printf("%02x",bs); } }
0
2481
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 hexadecimal value then it display an error Function GetXML(ByVal strTypeId As String) As String Dim xmlRef As New MSXML2.XMLHTTPClass Dim strUrl As String="Test.Asp"
0
8685
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9171
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9032
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8905
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7743
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6532
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2342
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.