Serializing XML with invalid characters

  • Thread starter Thread starter Rob Tillie
  • Start date Start date
R

Rob Tillie

Hey all,

I'm trying to serialize a class that has a strong password field in it, so it can contain characters like * or { or <. It serializes fine, but the deserializarion goed wrong, because it doesn't encode does characters.

I know that I can replace all strings with base64 equivalants, but isn't it possible to use some sort of attribute to tell the XmlSerializer that it should escape / handle my illegal characters?

Greetz,

-- Rob.
 
The only characters that have special meaning in XML are <, > and " (and "
only in elements, not in their contents). Everything else is game, as long
as it's properly encoded.

You need to translate those three characters to entities, can you post the
piece of code that writes the password out? I've never written custom
serialization myself so you have to show me the code.

Jerry

"Rob Tillie" </O=FLEP-TECH/OU=FIRST ADMINISTRATIVE
GROUP/CN=RECIPIENTS/CN=ROB> wrote in message
news:[email protected]...
 
Hello Jerry,

I didn't use custom serialization so I guess that is the problem :), so you implicitly answered my question.
So I should do the serialization myself and transform the fields to base64 encoding or something like that?
I hoped they had some kind of attribute to apply on a Property...

I did find on msdn that they have solved this in .NET 2.0, the thing automatically escapes / converts your data...

Greetz,
-- Rob.
 
No, you don't need to use base64 at all, all you have to do is encode <, >
and " to &lt;, &gt; and &quot;. This should've been done by the serializer,
let me give it a try, because if the serializer doesn't do that then you
found a bug in it.

Jerry

"Rob Tillie" </O=FLEP-TECH/OU=FIRST ADMINISTRATIVE
GROUP/CN=RECIPIENTS/CN=ROB> wrote in message
 
Hello Jerry,

I fixed it by using the SoapFormatter, this thing does correctly escape the characters.

Greetz,
-- Rob.
 
I'm trying to serialize a class that has a strong password field in it, so it can contain characters like * or { or <.
It serializes fine, but the deserializarion goed wrong, because it doesn't encode does characters.

Have a look at the XmlConvert class - it can encode / decode
"problematic" characters into codes that work just fine in
serialization.

Marc
================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
 
Back
Top