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

XmlSerializer Hexadecimal question

I have a webservice that returns data from a database.

Our services (the clients) have been blowing up because of illegal
character problems. Is there anything I can do on the server side to
work around this problem. I'm OK with deleting all the "bad"
characters.

I have a couple DTOs that are marked with [Serializable()] that I
return from the web service after they're populated with data from the
database. Is there some kind of attribute or "easy" way to stip out
illegal characters?

What is weird to me, is that the XmlSerializer serializes it just fine,
the clients are the ones blowing up. Here is the error I'm getting:

---------------------------------

System.InvalidOperationException: There is an error in XML document
(230, 966838). ---System.Xml.XmlException: '', hexadecimal value
0x04, is an invalid character. Line 230, position 966862.
at System.Xml.XmlScanner.ScanHexEntity()
at System.Xml.XmlTextReader.ParseBeginTagExpandCharEn tities()
at System.Xml.XmlTextReader.Read()
at System.Xml.XmlReader.ReadElementString()
at
Microsoft.Xml.Serialization.GeneratedAssembly.XmlS erializationReader1.Read11
_EVariable(Boolean isNullable, Boolean checkType) at
Microsoft.Xml.Serialization.GeneratedAssembly.XmlS erializationReader1.Read9_
EmailSpec(Boolean isNullable, Boolean checkType) at
Microsoft.Xml.Serialization.GeneratedAssembly.XmlS erializationReader1.Read8_
EmailInfo(Boolean isNullable, Boolean checkType) at
Microsoft.Xml.Serialization.GeneratedAssembly.XmlS erializationReader1.Read2_
CRobe(Boolean isNullable, Boolean checkType) at
Microsoft.Xml.Serialization.GeneratedAssembly.XmlS erializationReader1.Read28
_CRobeGetForGuidResponse()

--- End of inner exception stack trace ---

I do populate the object properties by looping through each DataRow in
a DataSet and accessing the dr[column]. Is there a function that will
stip out "illegal" characters?

Any help would be greatly appreciated.

Nov 30 '06 #1
4 4862
Is there anything in the "System.Text.Encoding" namespace that can help?
Nov 30 '06 #2
I found this article:

http://msdn.microsoft.com/library/de...trblshtxsd.asp

It says:
You can avoid this problem if you deserialize with an XmlTextReader that has
its Normalization property set to true. Unfortunately, the XmlTextReader
used under the covers by ASP.NET Web services has its Normalization property
set to false; i.e., it will not deserialize SOAP messages containing these
invalid characters.

Does this mean that I'm SOL?

Nov 30 '06 #3
So I've now opened up Reflector and started to examine the System.Xml
namespace.
I can see where the parsing is done, but it's a little too advanced for me.
It throws this error:

-----------------------
System.Xml.XmlException: '', hexadecimal value {0}, is an invalid character.
Line {1}, position {2}.
-----------------------

From the code 'this.ThrowInvalidChar(var, var)'.

Here is the code that determines if the character is 'bad':

-----------------------------------------------------------
char ch1 = chArray1[num1];
if ((ch1 >= 0xd800) && (ch1 <= 0xdbff))
{
if ((num1 + 1) == this.ps.charsUsed)
{
goto Label_02B3;
}
num1++;
if ((chArray1[num1] >= 0xdc00) && (chArray1[num1] <= 0xdfff))
{
num1++;
goto Label_0082;
}
}
this.ThrowInvalidChar(num1, ch1);
-----------------------------------------------------------

I've found this identitcal code in the following methods:

Sytem.Xml.XmlTextReaderImpl.ParseAttributeValueChu nk()
Sytem.Xml.XmlTextReaderImpl.ParseAttributeValueSlo w(...)
Sytem.Xml.XmlTextReaderImpl.ParseCDataOrComment(.. ..)
Sytem.Xml.XmlTextReaderImpl.ParseNumericCharRefInl ine(....)
Sytem.Xml.XmlTextReaderImpl.ParseIPValue(...)
Sytem.Xml.XmlTextReaderImpl.ParseRootLevelWhitespa ce()
Sytem.Xml.XmlTextReaderImpl.ParseText(....)
I am unsure what the significance of the hex values. It looks to me like
the jist of it is says that:

if ( !((ch1 >= 0xd800) && (ch1 <= 0xdbff)) && !((chArray1[num1+1] >= 0xdc00)
&& (chArray1[num1+1] <= 0xdfff)) )
myXmlData.replace(ch1,'');

I'm really stretching here....Any input would be appreciated.
Nov 30 '06 #4
Hello preport,

Regarding on this issue, I have also found your another thread in the
following newsgroup:

Subject: XmlSerializer Question

newsgroup: microsoft.public.dotnet.framework.webservices

I have posted some suggestion and information there. Please feel free to
followup if there is anything we can help.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Dec 1 '06 #5

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

Similar topics

4
by: James DeClerk | last post by:
Hi everyone. I'm new to C++ and I've got a seemingly tough problem to tackle. I have a union. This union needs to be converted into hexadecimal format. The hexadecimal number is then...
4
by: Andy Neilson | last post by:
I've run across a strange behaviour with XmlSerializer that I'm unable to explain. I came across this while trying to use XmlSerializer to deserialize from a the details of a SoapException. This...
16
by: Bob Rock | last post by:
Hello, when serializing an array of elements of a class Classname using XmlSerializer.Serialize() I get an XML like the following: <?xml version="1.0"> <ArrayOfClassname> ....... ..........
2
by: magister | last post by:
Hello I got this working but it is not how I really want it, basically I have an xml file which has a root of <test> and can be filled with 3 different types of <question> elements with different...
12
by: SJD | last post by:
I've just read Christoph Schittko's article on XmlSerializer: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnxmlnet/html/trblshtxsd.asp . . . and very informative it is too....
0
by: William Stacey [MVP] | last post by:
Had a method that got some string info from mp3 tags in N files and serializes this class and deserializes at other side. Works ok except sometimes get chars that choke the XmlSerializer. After...
1
by: Fernando Barsoba | last post by:
Hi all, First of all, I'd like to thank you "Skarmander" and "Flash Gordon" for the help they provided me: Skarmander's algorithm and Flash's modifications helped me a lot. Here's the problem...
15
by: jaks.maths | last post by:
How to convert negative integer to hexadecimal or octal number? Ex: -568 What is the equivalent hexadecimal and octal number??
6
by: preport | last post by:
I have a webservice that returns data from a database. Our services (the clients) have been blowing up because of illegal character problems. Is there anything I can do on the server side to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.