Patrice Calve

Life's short, have fun
posts - 51, comments - 49, trackbacks - 31

My Links

News

Archives

Post Categories

Image Galleries

Controling the Data saved during XmlSerializer

I had a problem where the data serialized got “messed up”.  It was a string that contained control chars (tabs, carriage return, line feed, etc.).

Without anything special, the serializer will just “dump” the content directly in the XML (as is).  Having XML what it is, it ignored these special characters when deserializing.

Let's say that the text to save is:
”Hi,

My name is John Doe”

There XML resulting in the serializer will become:

<...>

<myString>Hi,

My name is John Doe</myString>

</...>

 

When it gets deserialized, The Carriage Return gets lost.

 

Trick:

Add the following attribute

[XmlElement(DataType = "anyURI")]

public string myString

Pat

Print | posted on Thursday, March 30, 2006 12:50 PM |

Feedback

No comments posted yet.
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 

Powered by: