XMLSerializer \r\n problem<p align=left>Hi,</p> <p align=left> </p> <p align=left>I am using <font color="#008080" size=2>XmlSerializer <font color="#000000">to serialize an object to and from a database field. The target table has a text type field to hold the serialized object information (as an XML blob). I am using SQL Server 2000 and .Net 2.0. Most fields of the object serialize and deserialize fine except for strings. I have a string field storing some data that seems to come back slighty different. After debugging my code I have come to the conclusion that the XMLSerializer correctly writes strings to the database with \r\n intact but when deserializing, it returns strings with only \n. I have attached the code below.</font></font></p> <p align=left><font color="#008080" size=2><font color="#000000"></font></font> </p> <p align=left><font color="#008080" size=2><font color="#000000"></font> </p><font size=2> <p></font><font color="#008080" size=2>XmlSerializer</font><font size=2> xsz = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#008080" size=2>XmlSerializer</font><font size=2>(</font><font color="#0000ff" size=2>typeof</font><font size=2>(</font><font color="#008080" size=2>ComparisonOptions</font><font size=2>));</p> <p></font><font color="#008080" size=2>Options</font><font size=2> copt = </font><font color="#0000ff" size=2>null</font><font size=2>;</p> <p dir=ltr style="margin-right:0px"></font><font color="#0000ff" size=2>using</font><font size=2> (</font><font color="#008080" size=2>SqlConnection</font><font size=2> con = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#008080" size=2>SqlConnection</font><font size=2>(overlordDB))</p> <p dir=ltr style="margin-right:0px">{</p> <blockquote dir=ltr style="margin-right:0px"> <p dir=ltr style="margin-right:0px" align=left></font><font color="#0000ff" size=2>using</font><font size=2> (</font><font color="#008080" size=2>SqlCommand</font><font size=2> cmd = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#008080" size=2>SqlCommand</font><font size=2>(</font><font color="#800000" size=2>&quot;usp_GetRecord&quot;</font><font size=2>, con))</p> <p dir=ltr style="margin-right:0px">{</p> <blockquote dir=ltr style="margin-right:0px"> <p dir=ltr style="margin-right:0px">cmd.CommandType = </font><font color="#008080" size=2>CommandType</font><font size=2>.StoredProcedure;</p> <p dir=ltr style="margin-right:0px">cmd.Parameters.AddWithValue(</font><font color="#800000" size=2>&quot;@id&quot;</font><font size=2>, id);</p> <p dir=ltr style="margin-right:0px">con.Open();</p> <p dir=ltr style="margin-right:0px"></font><font color="#0000ff" size=2>using</font><font size=2> (</font><font color="#008080" size=2>SqlDataReader</font><font size=2> rdr = cmd.ExecuteReader())</p> <p dir=ltr style="margin-right:0px">{</p> <blockquote dir=ltr style="margin-right:0px"> <p dir=ltr style="margin-right:0px"></font><font color="#008080" size=2>Debug</font><font size=2>.Assert(rdr.RecordsAffected != 1);</p> <p dir=ltr style="margin-right:0px"></font><font color="#008000" size=2>//get the first recrod, we only expect one.</p></font><font size=2> <p dir=ltr style="margin-right:0px">rdr.Read();</p> <p dir=ltr style="margin-right:0px"></font><font color="#008080" size=2>StringReader</font><font size=2> str = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#008080" size=2>StringReader</font><font size=2>((</font><font color="#0000ff" size=2>string</font><font size=2>)rdr[</font><font color="#800000" size=2>&quot;Options&quot;</font><font size=2>]); --This line seems to read the string fine</p> <p dir=ltr style="margin-right:0px"></p> <p dir=ltr style="margin-right:0px">copt = (</font><font color="#008080" size=2>ComparisonOptions</font><font size=2>)xsz.Deserialize(str); --After this copt string fields are missing \r.</p> <p dir=ltr style="margin-right:0px">copt.ID = (</font><font color="#0000ff" size=2>int</font><font size=2>)rdr[</font><font color="#800000" size=2>&quot;ID&quot;</font><font size=2>];</p> <p dir=ltr style="margin-right:0px">copt.Name = (</font><font color="#0000ff" size=2>string</font><font size=2>)rdr[</font><font color="#800000" size=2>&quot;Name&quot;</font><font size=2>];</p> <p dir=ltr style="margin-right:0px">copt.Description = (</font><font color="#0000ff" size=2>string</font><font size=2>)rdr[</font><font color="#800000" size=2>&quot;Description&quot;</font><font size=2>];</p></blockquote> <p dir=ltr style="margin-right:0px">}</p></blockquote> <p dir=ltr style="margin-right:0px">}</p></blockquote> <p>}</p> <p> </p> <p align=left><font color="#000000">The Options object is being populated from the corresponding database text field. this object has a string field which is assigned via deserialization. I have run through the code with the debugger and at the point I have marked (StringReader str decleration and assignment) the string fields in the XML blob are all read in correctly from the database and have their \r\n intact. After deserializing in to copt, the string fields of copt have only \n.</font></p> <p align=left><font color="#000000"></font> </p> <p align=left><font color="#000000">There doesent seem to be anything I can find in the forums or on google that describes a similar sort of problem.</font></p> <p align=left><font color="#000000"></font> </p> <p align=left><font color="#000000">Any help would be greatly appreciated as I have hit a dead end with this.</font></font></font></p> <p> </p> <p align=left>Imran</p>© 2009 Microsoft Corporation. All rights reserved.Thu, 19 Jun 2008 00:15:52 Z1d3c0ed9-5f26-42b4-a441-b92096aace0ahttp://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/1d3c0ed9-5f26-42b4-a441-b92096aace0a#1d3c0ed9-5f26-42b4-a441-b92096aace0ahttp://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/1d3c0ed9-5f26-42b4-a441-b92096aace0a#1d3c0ed9-5f26-42b4-a441-b92096aace0aimran.ahttp://social.msdn.microsoft.com/Profile/en-US/?user=imran.aXMLSerializer \r\n problem<p align=left>Hi,</p> <p align=left> </p> <p align=left>I am using <font color="#008080" size=2>XmlSerializer <font color="#000000">to serialize an object to and from a database field. The target table has a text type field to hold the serialized object information (as an XML blob). I am using SQL Server 2000 and .Net 2.0. Most fields of the object serialize and deserialize fine except for strings. I have a string field storing some data that seems to come back slighty different. After debugging my code I have come to the conclusion that the XMLSerializer correctly writes strings to the database with \r\n intact but when deserializing, it returns strings with only \n. I have attached the code below.</font></font></p> <p align=left><font color="#008080" size=2><font color="#000000"></font></font> </p> <p align=left><font color="#008080" size=2><font color="#000000"></font> </p><font size=2> <p></font><font color="#008080" size=2>XmlSerializer</font><font size=2> xsz = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#008080" size=2>XmlSerializer</font><font size=2>(</font><font color="#0000ff" size=2>typeof</font><font size=2>(</font><font color="#008080" size=2>ComparisonOptions</font><font size=2>));</p> <p></font><font color="#008080" size=2>Options</font><font size=2> copt = </font><font color="#0000ff" size=2>null</font><font size=2>;</p> <p dir=ltr style="margin-right:0px"></font><font color="#0000ff" size=2>using</font><font size=2> (</font><font color="#008080" size=2>SqlConnection</font><font size=2> con = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#008080" size=2>SqlConnection</font><font size=2>(overlordDB))</p> <p dir=ltr style="margin-right:0px">{</p> <blockquote dir=ltr style="margin-right:0px"> <p dir=ltr style="margin-right:0px" align=left></font><font color="#0000ff" size=2>using</font><font size=2> (</font><font color="#008080" size=2>SqlCommand</font><font size=2> cmd = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#008080" size=2>SqlCommand</font><font size=2>(</font><font color="#800000" size=2>&quot;usp_GetRecord&quot;</font><font size=2>, con))</p> <p dir=ltr style="margin-right:0px">{</p> <blockquote dir=ltr style="margin-right:0px"> <p dir=ltr style="margin-right:0px">cmd.CommandType = </font><font color="#008080" size=2>CommandType</font><font size=2>.StoredProcedure;</p> <p dir=ltr style="margin-right:0px">cmd.Parameters.AddWithValue(</font><font color="#800000" size=2>&quot;@id&quot;</font><font size=2>, id);</p> <p dir=ltr style="margin-right:0px">con.Open();</p> <p dir=ltr style="margin-right:0px"></font><font color="#0000ff" size=2>using</font><font size=2> (</font><font color="#008080" size=2>SqlDataReader</font><font size=2> rdr = cmd.ExecuteReader())</p> <p dir=ltr style="margin-right:0px">{</p> <blockquote dir=ltr style="margin-right:0px"> <p dir=ltr style="margin-right:0px"></font><font color="#008080" size=2>Debug</font><font size=2>.Assert(rdr.RecordsAffected != 1);</p> <p dir=ltr style="margin-right:0px"></font><font color="#008000" size=2>//get the first recrod, we only expect one.</p></font><font size=2> <p dir=ltr style="margin-right:0px">rdr.Read();</p> <p dir=ltr style="margin-right:0px"></font><font color="#008080" size=2>StringReader</font><font size=2> str = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#008080" size=2>StringReader</font><font size=2>((</font><font color="#0000ff" size=2>string</font><font size=2>)rdr[</font><font color="#800000" size=2>&quot;Options&quot;</font><font size=2>]); --This line seems to read the string fine</p> <p dir=ltr style="margin-right:0px"></p> <p dir=ltr style="margin-right:0px">copt = (</font><font color="#008080" size=2>ComparisonOptions</font><font size=2>)xsz.Deserialize(str); --After this copt string fields are missing \r.</p> <p dir=ltr style="margin-right:0px">copt.ID = (</font><font color="#0000ff" size=2>int</font><font size=2>)rdr[</font><font color="#800000" size=2>&quot;ID&quot;</font><font size=2>];</p> <p dir=ltr style="margin-right:0px">copt.Name = (</font><font color="#0000ff" size=2>string</font><font size=2>)rdr[</font><font color="#800000" size=2>&quot;Name&quot;</font><font size=2>];</p> <p dir=ltr style="margin-right:0px">copt.Description = (</font><font color="#0000ff" size=2>string</font><font size=2>)rdr[</font><font color="#800000" size=2>&quot;Description&quot;</font><font size=2>];</p></blockquote> <p dir=ltr style="margin-right:0px">}</p></blockquote> <p dir=ltr style="margin-right:0px">}</p></blockquote> <p>}</p> <p> </p> <p align=left><font color="#000000">The Options object is being populated from the corresponding database text field. this object has a string field which is assigned via deserialization. I have run through the code with the debugger and at the point I have marked (StringReader str decleration and assignment) the string fields in the XML blob are all read in correctly from the database and have their \r\n intact. After deserializing in to copt, the string fields of copt have only \n.</font></p> <p align=left><font color="#000000"></font> </p> <p align=left><font color="#000000">There doesent seem to be anything I can find in the forums or on google that describes a similar sort of problem.</font></p> <p align=left><font color="#000000"></font> </p> <p align=left><font color="#000000">Any help would be greatly appreciated as I have hit a dead end with this.</font></font></font></p> <p> </p> <p align=left>Imran</p>Wed, 02 Apr 2008 14:31:15 Z2008-04-04T11:31:23Zhttp://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/1d3c0ed9-5f26-42b4-a441-b92096aace0a#04ee890e-ceed-480a-b291-37bd13707c5bhttp://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/1d3c0ed9-5f26-42b4-a441-b92096aace0a#04ee890e-ceed-480a-b291-37bd13707c5bNetwhizhttp://social.msdn.microsoft.com/Profile/en-US/?user=NetwhizXMLSerializer \r\n problemHello,<br><br>Are you using XmlWriter in your serialize function, if so I think you can use the XmlWriterSettings to persist your indents.<br><br>Thanks<br>Netwhiz<br>Wed, 02 Apr 2008 18:16:39 Z2008-04-02T18:16:39Zhttp://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/1d3c0ed9-5f26-42b4-a441-b92096aace0a#30a39ec8-e219-4c48-9166-e838e173fb9fhttp://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/1d3c0ed9-5f26-42b4-a441-b92096aace0a#30a39ec8-e219-4c48-9166-e838e173fb9fthoward37http://social.msdn.microsoft.com/Profile/en-US/?user=thoward37XMLSerializer \r\n problem<p>To help isolate the problem, remove the database from the picture in a small test harness. Simply serialize the data to an xml string, then immediately deserialize it to an object again. See if you're missing the '\r' in the final object.</p> <p align=left> </p> <p align=left>If so, the problem is within the XmlSerializer settings. If not, then problem is related to database storage and retrieval. </p> <p align=left> </p> <p align=left>I regularly serialize and deserialize objects with string data the contains CR/LF, and I've never run into issue like that, and I don't use any special XmlSerializer configuration.. Just out of the box. I imagine it has something to do with the insert to the database, converting the line endings. </p> <p align=left> </p> <p align=left>What datatype is the DB field where this is being stored? Are you using a stored proc through a SqlCommand<font size=2> object for the insert as well, or using an dynamic query? If it's a stored proc, does the parameter of the stored proc for passing the xml data match the DB field type or are you using on the sql convert functions to get it to match? </font></p> <p align=left> </p> <p align=left>What is the collation setting for the database?</p> <p align=left> </p> <p align=left>Hope that helps,</p> <p align=left>Troy</p> <p align=left> </p> <p align=left><font face=Arial size=2></font> </p>Wed, 02 Apr 2008 21:39:26 Z2008-04-02T21:39:26Zhttp://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/1d3c0ed9-5f26-42b4-a441-b92096aace0a#3893be13-f300-4ef7-beaf-e39729b3f487http://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/1d3c0ed9-5f26-42b4-a441-b92096aace0a#3893be13-f300-4ef7-beaf-e39729b3f487imran.ahttp://social.msdn.microsoft.com/Profile/en-US/?user=imran.aXMLSerializer \r\n problem<p>Hi Guys,</p> <p align=left> </p> <p align=left>Nope, I am not using XmlWriter I am using StringWriter. From what I can see the problem doesent seem to be perisisng the objects to the database as the \r\n control chars are intact at this point and it is demonstrated in the below test when you step through witht he debugger. The test below demonstrates my problem.</p> <p align=left> </p><font size=2><font color="#0000ff" size=2> <p>using</font><font size=2> System;</p></font><font color="#0000ff" size=2> <p>using</font><font size=2> System.IO;</p></font><font color="#0000ff" size=2> <p>using</font><font size=2> System.Xml.Serialization;</p></font><font color="#0000ff" size=2> <p>using</font><font size=2> System.Xml;</p></font><font color="#0000ff" size=2> <p>namespace</font><font size=2> TestXmlSerializecrlf</p> <p>{</p> <p></font><font color="#0000ff" size=2>internal</font><font size=2> </font><font color="#0000ff" size=2>class</font><font size=2> </font><font color="#008080" size=2>Program</p></font><font size=2> <p>{</p> <p></font><font color="#0000ff" size=2>static</font><font size=2> </font><font color="#0000ff" size=2>readonly</font><font size=2> </font><font color="#0000ff" size=2>string</font><font size=2> orig = </font><font color="#800000" size=2>@&quot;multiline input</p> <p>another line here</p> <p>one more line&quot;</font><font size=2>;</p> <p></font><font color="#0000ff" size=2>private</font><font size=2> </font><font color="#0000ff" size=2>static</font><font size=2> </font><font color="#0000ff" size=2>void</font><font size=2> Main(</font><font color="#0000ff" size=2>string</font><font size=2>[] args)</p> <p>{</p> <p>serialize();</p> <p>deserialize();</p> <p></font><font color="#008080" size=2>Console</font><font size=2>.ReadLine();</p> <p>}</p> <p></font><font color="#0000ff" size=2>private</font><font size=2> </font><font color="#0000ff" size=2>static</font><font size=2> </font><font color="#0000ff" size=2>void</font><font size=2> serialize()</p> <p>{</p> <p></font><font color="#008000" size=2>//Serialize</p></font><font size=2> <p></font><font color="#008080" size=2>XmlSerializer</font><font size=2> xsz = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#008080" size=2>XmlSerializer</font><font size=2>(</font><font color="#0000ff" size=2>typeof</font><font size=2> (</font><font color="#008080" size=2>TestObj</font><font size=2>));</p> <p></font><font color="#008080" size=2>StringWriter</font><font size=2> sWriter = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#008080" size=2>StringWriter</font><font size=2>();</p> <p></font><font color="#008080" size=2>TestObj</font><font size=2> to = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#008080" size=2>TestObj</font><font size=2>();</p> <p>to.txt = orig;</p> <p></p> <p>xsz.Serialize(sWriter, to);</p> <p></font><font color="#008000" size=2>//write</p></font><font size=2> <p></font><font color="#0000ff" size=2>using</font><font size=2> (</font><font color="#008080" size=2>StreamWriter</font><font size=2> sw = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#008080" size=2>StreamWriter</font><font size=2>(</font><font color="#800000" size=2>@&quot;C:\TestFile.txt&quot;</font><font size=2>, </font><font color="#0000ff" size=2>false</font><font size=2>))</p> <p>{</p> <p>sw.Write(sWriter.ToString());</p> <p>}</p> <p>}</p> <p></font><font color="#0000ff" size=2>private</font><font size=2> </font><font color="#0000ff" size=2>static</font><font size=2> </font><font color="#0000ff" size=2>void</font><font size=2> deserialize()</p> <p>{</p> <p></font><font color="#008000" size=2>//Deserialize</p></font><font size=2> <p></font><font color="#008080" size=2>XmlSerializer</font><font size=2> xsz = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#008080" size=2>XmlSerializer</font><font size=2>(</font><font color="#0000ff" size=2>typeof</font><font size=2> (</font><font color="#008080" size=2>TestObj</font><font size=2>));</p> <p></font><font color="#008080" size=2>TestObj</font><font size=2> to = </font><font color="#0000ff" size=2>null</font><font size=2>;</p> <p></font><font color="#0000ff" size=2>using</font><font size=2> (</font><font color="#008080" size=2>StreamReader</font><font size=2> sr = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#008080" size=2>StreamReader</font><font size=2>(</font><font color="#800000" size=2>@&quot;C:\TestFile.txt&quot;</font><font size=2>))</p> <p>{</p> <p></font><font color="#008080" size=2>StringReader</font><font size=2> str = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#008080" size=2>StringReader</font><font size=2>(sr.ReadToEnd()); --Here the string is intact</p> <p>to = (</font><font color="#008080" size=2>TestObj</font><font size=2>) xsz.Deserialize(str); --Here it isnt</p> <p>}</p> <p></font><font color="#0000ff" size=2>if</font><font size=2> (to.txt != orig)</p> <p>{</p> <p></font><font color="#008080" size=2>Console</font><font size=2>.Write(</font><font color="#800000" size=2>&quot;Strings are not equal&quot;</font><font size=2>);</p> <p>}</p> <p></font><font color="#0000ff" size=2>else</p></font><font size=2> <p>{</p> <p></font><font color="#008080" size=2>Console</font><font size=2>.Write(</font><font color="#800000" size=2>&quot;Strings are equal&quot;</font><font size=2>);</p> <p>}</p> <p>}</p> <p>}</p> <p>[</font><font color="#008080" size=2>Serializable</font><font size=2>]</p> <p></font><font color="#0000ff" size=2>public</font><font size=2> </font><font color="#0000ff" size=2>class</font><font size=2> </font><font color="#008080" size=2>TestObj</p></font><font size=2> <p>{</p> <p></font><font color="#0000ff" size=2>public</font><font size=2> </font><font color="#0000ff" size=2>string</font><font size=2> txt;</p> <p>}</p> <p>}</p> <p> </p> <p align=left>This test reproduces the error. If you step through this code with the debugger you will see that the string read back in has \r\n chars intact. after deserialization however, it only has \n. This is causing a problem for me at the moment because i am saving some user input from a text box and when it is loaded again it comes back incorrectly formatted. As i said before I am using sql server 2000 and the xml blob is stored in a text field. Also the sql sp expects a text paramater so there is no need for any conversion functions within the sp or my ADO.NET code. Database collation is set to Latin1_General_CI_AS however, i think we have eliminated teh db from the problem with the above code.</p> <p align=left> </p> <p align=left>Any Ideas?</font></font></p>Thu, 03 Apr 2008 09:44:01 Z2008-04-03T09:44:01Zhttp://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/1d3c0ed9-5f26-42b4-a441-b92096aace0a#0ec78237-c282-4e4d-9d88-c1bf0e7541aahttp://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/1d3c0ed9-5f26-42b4-a441-b92096aace0a#0ec78237-c282-4e4d-9d88-c1bf0e7541aaJohn Saundershttp://social.msdn.microsoft.com/Profile/en-US/?user=John%20SaundersXMLSerializer \r\n problem<p>The trick is in looking at the XML to which your class gets serialized. You will find that the &quot;txt&quot; field gets serialized as the value of an element called &quot;txt&quot;. The same happens if you use the [XmlText] attribute to cause it to be serialized as a text node.</p> <p align=left> </p> <p align=left>It gets serialized as you specified it, with \r\n. However, in XML, \r\n is just whitespace, and is equivalent to \n. This is what it gets turned into when it is deserialized.</p> <p align=left> </p> <p align=left>I think you may need to implement IXmlSerializable and to write &quot;txt&quot; in a CDATA section. That way, it should be deserialized character for character as you wrote it. </p> <p align=left> </p> <p align=left>Alternatively, you could serialize your string as binary:</p> <p align=left> </p> <p class=MsoNormal style="margin:0in 0in 0pt" align=left><span style="font-size:10pt;font-family:'Lucida Console'"> <div class=codeseg> <div class=codecontent> <div class=codesniptitle><span style="width:100%">Code Snippet</span></div> <p class=MsoNormal style="margin:0in 0in 0pt" align=left><span style="font-size:10pt;font-family:'Lucida Console'">[<span style="color:#2b91af">Serializable</span>]</span></p> <p class=MsoNormal style="margin:0in 0in 0pt" align=left><span style="font-size:10pt;color:blue;font-family:'Lucida Console'">public</span><span style="font-size:10pt;font-family:'Lucida Console'"> <span style="color:blue">class</span> <span style="color:#2b91af">TestObj</span></span></p> <p class=MsoNormal style="margin:0in 0in 0pt" align=left><span style="font-size:10pt;font-family:'Lucida Console'">{</span></p> <p class=MsoNormal style="margin:0in 0in 0pt" align=left><span style="font-size:10pt;font-family:'Lucida Console'"><span style="">    </span>[<span style="color:#2b91af">XmlIgnore</span>]</span></p> <p class=MsoNormal style="margin:0in 0in 0pt" align=left><span style="font-size:10pt;font-family:'Lucida Console'"><span style="">    </span><span style="color:blue">public</span> <span style="color:blue">string</span> txt;</span></p> <p class=MsoNormal style="margin:0in 0in 0pt" align=left><span style="font-size:10pt;font-family:'Lucida Console'"> </span></p> <p class=MsoNormal style="margin:0in 0in 0pt" align=left><span style="font-size:10pt;font-family:'Lucida Console'"><span style="">    </span>[<span style="color:#2b91af">XmlElement</span>(ElementName = <span style="color:#a31515">&quot;txt&quot;</span>, DataType = <span style="color:#a31515">&quot;base64Binary&quot;</span>)]</span></p> <p class=MsoNormal style="margin:0in 0in 0pt" align=left><span style="font-size:10pt;font-family:'Lucida Console'"><span style="">    </span><span style="color:blue">public</span> <span style="color:blue">byte</span>[] txtSerialization</span></p> <p class=MsoNormal style="margin:0in 0in 0pt" align=left><span style="font-size:10pt;font-family:'Lucida Console'"><span style="">    </span>{</span></p> <p class=MsoNormal style="margin:0in 0in 0pt" align=left><span style="font-size:10pt;font-family:'Lucida Console'"><span style="">        </span><span style="color:blue">get</span></span></p> <p class=MsoNormal style="margin:0in 0in 0pt" align=left><span style="font-size:10pt;font-family:'Lucida Console'"><span style="">        </span>{</span></p> <p class=MsoNormal style="margin:0in 0in 0pt" align=left><span style="font-size:10pt;font-family:'Lucida Console'"><span style="">            </span><span style="color:blue">return</span> System.Text.<span style="color:#2b91af">Encoding</span>.Unicode.GetBytes(txt);</span></p> <p class=MsoNormal style="margin:0in 0in 0pt" align=left><span style="font-size:10pt;font-family:'Lucida Console'"><span style="">        </span>}</span></p> <p class=MsoNormal style="margin:0in 0in 0pt" align=left><span style="font-size:10pt;font-family:'Lucida Console'"><span style="">        </span><span style="color:blue">set</span></span></p> <p class=MsoNormal style="margin:0in 0in 0pt" align=left><span style="font-size:10pt;font-family:'Lucida Console'"><span style="">        </span>{</span></p> <p class=MsoNormal style="margin:0in 0in 0pt" align=left><span style="font-size:10pt;font-family:'Lucida Console'"><span style="">            </span>txt = System.Text.<span style="color:#2b91af">Encoding</span>.Unicode.GetString(<span style="color:blue">value</span>);</span></p> <p class=MsoNormal style="margin:0in 0in 0pt" align=left><span style="font-size:10pt;font-family:'Lucida Console'"><span style="">        </span>}</span></p> <p class=MsoNormal style="margin:0in 0in 0pt" align=left><span style="font-size:10pt;font-family:'Lucida Console'"><span style="">    </span>}</span></p> <p class=MsoNormal style="margin:0in 0in 0pt" align=left><span style="font-size:10pt;font-family:'Lucida Console'">}</span></p> <p align=left> </p></div></div> <p align=left> </p></span> <p></p> <p class=MsoNormal style="margin:0in 0in 0pt"><font face="Times New Roman" size=3></font> </p>Thu, 03 Apr 2008 14:13:30 Z2008-04-03T14:13:30Zhttp://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/1d3c0ed9-5f26-42b4-a441-b92096aace0a#1cec0787-3dfc-4f97-b28b-335570c90705http://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/1d3c0ed9-5f26-42b4-a441-b92096aace0a#1cec0787-3dfc-4f97-b28b-335570c90705imran.ahttp://social.msdn.microsoft.com/Profile/en-US/?user=imran.aXMLSerializer \r\n problem<p>John,</p> <p align=left>I will look in to implementing IXmlSerializable as binary blobs are probably not an option for me. I can understand white space being omitted/stripped or converted for the actual xml elements but as for the actual data they hold, this shouldnt be modified. Surely this is a bug in the XmlSerializer as this is altering persisted data?</p> <p align=left><font face=Arial size=2></font> </p>ImranThu, 03 Apr 2008 16:50:23 Z2008-04-03T16:50:23Zhttp://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/1d3c0ed9-5f26-42b4-a441-b92096aace0a#19b84427-6272-44a2-b85b-7ae10610e5d9http://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/1d3c0ed9-5f26-42b4-a441-b92096aace0a#19b84427-6272-44a2-b85b-7ae10610e5d9thoward37http://social.msdn.microsoft.com/Profile/en-US/?user=thoward37XMLSerializer \r\n problem<p>Oh! I see the problem. </p> <p align=left> </p> <p align=left>Don't use StreamReader... use XmlTextReader.</p> <p align=left> </p> <p align=left>Here's the deserialize method with XmlTextReader...</p> <p align=left> </p> <p align=left> <div class=codeseg> <div class=codecontent> <div class=codesniptitle><span style="width:100%">Code Snippet</span></div> <p align=left> </p><font size=2> <p align=left></font><font color="#0000ff" size=2>private</font><font size=2> </font><font color="#0000ff" size=2>static</font><font size=2> </font><font color="#0000ff" size=2>void</font><font size=2> deserialize()</p> <p align=left>{ </p> <blockquote dir=ltr style="margin-right:0px"> <p align=left></font><font color="#2b91af" size=2>XmlSerializer</font><font size=2> xsz = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#2b91af" size=2>XmlSerializer</font><font size=2>(</font><font color="#0000ff" size=2>typeof</font><font size=2>(</font><font color="#2b91af" size=2>TestObj</font><font size=2>));</p> <p align=left></font><font color="#2b91af" size=2>TestObj</font><font size=2> to = </font><font color="#0000ff" size=2>null</font><font size=2>;</font></p> <p align=left><font size=2> </p> <p align=left></font><font color="#0000ff" size=2>using</font><font size=2> (</font><font color="#2b91af" size=2>XmlTextReader</font><font size=2> sr = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#2b91af" size=2>XmlTextReader</font><font size=2>(</font><font color="#a31515" size=2>@&quot;C:\TestFile.txt&quot;</font><font size=2>)) </p> <p align=left>{</p> <blockquote dir=ltr style="margin-right:0px"> <p align=left>to = (</font><font color="#2b91af" size=2>TestObj</font><font size=2>)xsz.Deserialize(sr);</p></blockquote> <p align=left>}</p> <p align=left></font><font color="#0000ff" size=2></font> </p> <p align=left><font color="#0000ff" size=2>if</font><font size=2> (to.txt != orig)</p> <p align=left>{</p> <blockquote dir=ltr style="margin-right:0px"> <p align=left></font><font color="#2b91af" size=2>Console</font><font size=2>.Write(</font><font color="#a31515" size=2>&quot;Strings are not equal&quot;</font><font size=2>);</p></blockquote> <p align=left>}</p> <p align=left></font><font color="#0000ff" size=2>else</p></font><font size=2> <p align=left>{</p> <blockquote dir=ltr style="margin-right:0px"> <p align=left></font><font color="#2b91af" size=2>Console</font><font size=2>.Write(</font><font color="#a31515" size=2>&quot;Strings are equal&quot;</font><font size=2>);</p></blockquote> <p align=left>}</p></blockquote> <p align=left>}</p></font> <p align=left> </p></div></div> <p align=left> </p> <p></p><font size=2> <p align=left></p> <p> </p> <p align=left>If you already have a StreamReader, and want to use it.. you can construct XmlTextReader with a stream instead of a filepath/url.</p> <p align=left> </p> <p align=left>Hope that helps,</p> <p align=left>Troy</p> <p align=left></font> </p>Thu, 03 Apr 2008 17:16:58 Z2008-04-03T17:16:58Zhttp://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/1d3c0ed9-5f26-42b4-a441-b92096aace0a#e103fa60-b122-4129-974e-013572aa2855http://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/1d3c0ed9-5f26-42b4-a441-b92096aace0a#e103fa60-b122-4129-974e-013572aa2855John Saundershttp://social.msdn.microsoft.com/Profile/en-US/?user=John%20SaundersXMLSerializer \r\n problem<p>Go ahead and try the XmlReader, but if you're using .NET 2.0 or above, you should use:</p> <p align=left> </p> <p align=left> <div class=codeseg> <div class=codecontent> <div class=codesniptitle><span style="width:100%">Code Snippet</span></div> <p align=left>using (XmlReader sr = XmlReader.Create(@&quot;C:\TestFile.txt&quot;))</p> <p align=left> </p></div></div> <p align=left> </p> <p></p> <p align=left>instead.</p> <p align=left><font face=Arial size=2></font> </p>Thu, 03 Apr 2008 17:19:30 Z2008-04-03T17:19:30Zhttp://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/1d3c0ed9-5f26-42b4-a441-b92096aace0a#7aaca727-fd87-45d2-b853-10a4a14fff6ehttp://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/1d3c0ed9-5f26-42b4-a441-b92096aace0a#7aaca727-fd87-45d2-b853-10a4a14fff6ethoward37http://social.msdn.microsoft.com/Profile/en-US/?user=thoward37XMLSerializer \r\n problem<p align=left><font face=Arial size=2>XmlReader also removes the carriage return characters... </font><font face=Arial size=2>XmlTextReader preserves them.</font></p> <p align=left> </p> <p align=left>XmlTextReader on MSDN</p> <p align=left><a title="http://msdn2.microsoft.com/en-us/library/system.xml.xmltextreader.aspx" href="http://msdn2.microsoft.com/en-us/library/system.xml.xmltextreader.aspx">http://msdn2.microsoft.com/en-us/library/system.xml.xmltextreader.aspx</a></p> <p align=left> </p> <p align=left>Thanks,<br>Troy</p> <p align=left> </p> <p align=left> </p> <p align=left> </p>Thu, 03 Apr 2008 17:25:38 Z2008-04-03T17:25:38Zhttp://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/1d3c0ed9-5f26-42b4-a441-b92096aace0a#fc6ccecf-2474-4b5a-a744-d0a4c8e0136fhttp://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/1d3c0ed9-5f26-42b4-a441-b92096aace0a#fc6ccecf-2474-4b5a-a744-d0a4c8e0136fJohn Saundershttp://social.msdn.microsoft.com/Profile/en-US/?user=John%20SaundersXMLSerializer \r\n problem<p>Careful reading of the documentation on XmlTextReader does mention that it does not normalize text nodes. I'm not sure that this is a good thing in general. In general, you want text nodes normalized. In tihs particular case, for this particular element, you don't.</p> <p align=left> </p> <p align=left>This appears to be a behavior of XmlReaders. Even when you specify a Stream or TextReader to DeSerialize, it internally creates and uses an XmlReader. It no doubt uses XmlReader.Create to create this internal XmlReader, and that is documented to normalize newlines.</p> <p align=left> </p> <p align=left>So, this problem could be simplified to an example of just using an XmlReader to read from a document that has \r\n within a text value. The question would be whether the \r\n is returned when the data is read. The goal would be to find a setting of XmlReader that will preserve the \r\n.</p> <p align=left> </p> <p align=left>With this example in hand, I'd suggest you experiment to see what happens if the element has xml: space='preserve'.  If it correctly returns \r\n, then the trick would be to cause xml<img alt="Tongue Tied" src="http://forums.microsoft.com/MSDN/emoticons/emotion-7.gif">pace='preserve' to be emitted on the &lt;txt/&gt; element.</p>Thu, 03 Apr 2008 19:15:42 Z2008-04-03T19:15:42Zhttp://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/1d3c0ed9-5f26-42b4-a441-b92096aace0a#440f4a0e-9653-40a6-822c-6dde80974825http://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/1d3c0ed9-5f26-42b4-a441-b92096aace0a#440f4a0e-9653-40a6-822c-6dde80974825John Saundershttp://social.msdn.microsoft.com/Profile/en-US/?user=John%20SaundersXMLSerializer \r\n problem<p>A search of MSDN found <a title="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1323184&amp;SiteID=1" href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1323184&amp;SiteID=1">http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1323184&amp;SiteID=1</a>. Also see the other hits on <a title="http://search.msdn.microsoft.com/Default.aspx?brand=Msdn&amp;refinement=00&amp;locale=en-us&amp;lang=en-us&amp;query=xmlserializer%20whitespace%20preserve" href="http://search.msdn.microsoft.com/Default.aspx?brand=Msdn&amp;refinement=00&amp;locale=en-us&amp;lang=en-us&amp;query=xmlserializer whitespace preserve">http://search.msdn.microsoft.com/Default.aspx?brand=Msdn&amp;refinement=00&amp;locale=en-us&amp;lang=en-us&amp;query=xmlserializer%20whitespace%20preserve</a>.</p> <p align=left> </p>Thu, 03 Apr 2008 19:34:45 Z2008-04-03T19:34:45Zhttp://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/1d3c0ed9-5f26-42b4-a441-b92096aace0a#a30977f1-7a0d-45aa-bd9e-92ed40eb8dc8http://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/1d3c0ed9-5f26-42b4-a441-b92096aace0a#a30977f1-7a0d-45aa-bd9e-92ed40eb8dc8thoward37http://social.msdn.microsoft.com/Profile/en-US/?user=thoward37XMLSerializer \r\n problem<p align=left>Arggg... I typed a lengthy explanation, only to find that when I hit &quot;post&quot; I had been logged out because my session expired. So it didn't post, and wasn't there when I hit the back button. </p> <p align=left> </p> <p align=left>I'll try to re-write the important parts quickly... I was probably too long winded in the first post anyway. </p> <p align=left> </p> <p align=left>In short -- you can control the level of whitespace handling with the WhiteSpaceHandling property on XmlTextReader. It defaults to WhiteSpaceHandling.All which gives you a lot of extra whitespace you might not want... I often use it iwth WhiteSpaceHandling.Significant to avoid this. Just set the property after you instantiate... </p> <p align=left> </p> <p align=left>If you dig around in Reflector you will see this is the only way to get it to work. Look at System.Xml.XmlTextReaderImpl. The GetWhiteSpaceType() method is what controls if it will pay attention to whitespace or not. This will only consider keeping the anything considered XmlNodeType.Whitespace or SignificantWhitespace (ie. newlines in your data) if the WhiteSpaceHandling value is either All or Signficant. Otherwise it pretends the whitespace doesn't exist, and returns XmlNodeType.None... which means it doesn't ever get to the method EatWhiteSpaces() which is where the Normalization value is checked before chomping the carriage return. </p> <p align=left> </p> <p align=left>So, unfortunately... Using the xml<img alt="Tongue Tied" src="http://forums.microsoft.com/MSDN/emoticons/emotion-7.gif">pace=&quot;preserve&quot; attribute on individual nodes won't work due to the implementation of the parser. The only way it will get those carriage returns data is with Normalization turned off. </p> <p align=left> </p> <p align=left>I'd be interested to hear if anyone can find a way to make that work!</p> <p align=left> </p> <p align=left>Hope that helps, </p> <p align=left>Troy</p>Thu, 03 Apr 2008 21:03:00 Z2008-04-03T21:03:00Zhttp://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/1d3c0ed9-5f26-42b4-a441-b92096aace0a#e06152ec-1c6f-411d-87be-65d0bc39688fhttp://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/1d3c0ed9-5f26-42b4-a441-b92096aace0a#e06152ec-1c6f-411d-87be-65d0bc39688fJohn Saundershttp://social.msdn.microsoft.com/Profile/en-US/?user=John%20SaundersXMLSerializer \r\n problem<p>Troy,</p> <p align=left> </p> <p align=left>In your Reflector research, did you determine whether there's a way to change the whitespace handling of the other derived XmlReader classes? I know that only XmlTextReader still has the WhitespaceHandling property, but do any of the other XmlReader implementations have a way to change the handling of whitespace? I'm talking .NET 2.0 and above, which is quite different from .NET 1.1.</p> <p align=left><font face=Arial size=2></font> </p>Thu, 03 Apr 2008 21:06:57 Z2008-04-03T21:06:57Zhttp://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/1d3c0ed9-5f26-42b4-a441-b92096aace0a#e2c839b3-91ac-4200-8f48-a12296ee36e6http://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/1d3c0ed9-5f26-42b4-a441-b92096aace0a#e2c839b3-91ac-4200-8f48-a12296ee36e6thoward37http://social.msdn.microsoft.com/Profile/en-US/?user=thoward37XMLSerializer \r\n problem<p>From what I can tell all the other non-abstract XmlReader implementations use the XmlTextReader under the hood. They just put more layers of business logic on top of it. </p> <p align=left> </p> <p align=left>None of the others seem to directly parse the text, but rather work with the abstracted objects produced by XmlTextReaderImpl's parsing stage. </p> <p align=left> </p> <p align=left>Of course, I could be wrong about that... There's a lot of code to look through. </p> <p align=left> </p> <p align=left>Also interesting to note that if you create the XmlReader via XmlReader.Create, and pass a XmlReaderSettings object, that the XmlReaderSettings object only allows you to control it's handling of &quot;insignificant&quot; whitespace via the IgnoreWhitespace property.. It doesn't have a property for controlling normalization, as the XmlTextReader does. </p> <p align=left> </p> <p align=left>Also interesting is that all the concrete implementations use the wrapper pattern, instead of an inheritance pattern, so even though they are all XmlReaders, and they all use a XmlTextReader under-the-hood, they use it by keeping XmlTextReader instance in a private field, rather than inheriting from it. I'm not sure what the motivation was behind that, but it means that you can't downcast the other concrete implementations to XmlTextReader, only to XmlReader... which is more limited. </p> <p align=left> </p> <p align=left> </p> <p align=left>Anyhow, for the OP's original example.. you probably want code that looks like this:</p> <p align=left> </p><font color="#2b91af" size=2> <p align=left> <div class=codeseg> <div class=codecontent> <div class=codesniptitle><span style="width:100%">Code Snippet</span></div><font color="#2b91af" size=2> <p align=left> </p> <p align=left>XmlSerializer</font><font size=2> xsz = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#2b91af" size=2>XmlSerializer</font><font size=2>(</font><font color="#0000ff" size=2>typeof</font><font size=2>(</font><font color="#2b91af" size=2>ComparisonOptions</font><font size=2>));</p></font><font color="#2b91af" size=2> <p align=left> </p> <p align=left>Options</font><font size=2> copt = </font><font color="#0000ff" size=2>null</font><font size=2>;</p></font><font color="#0000ff" size=2> <p align=left> </p> <p align=left>using</font><font size=2> (</font><font color="#2b91af" size=2>SqlConnection</font><font size=2> con = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#2b91af" size=2>SqlConnection</font><font size=2>(overlordDB))</p></font><font color="#0000ff" size=2> <p align=left>using</font><font size=2> (</font><font color="#2b91af" size=2>SqlCommand</font><font size=2> cmd = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#2b91af" size=2>SqlCommand</font><font size=2>(</font><font color="#a31515" size=2>&quot;usp_GetRecord&quot;</font><font size=2>, con))</p> <p align=left>{</p> <blockquote dir=ltr style="margin-right:0px"> <p align=left>cmd.CommandType = CommandType.StoredProcedure;</p> <p align=left>cmd.Parameters.AddWithValue(</font><font color="#a31515" size=2>&quot;@id&quot;</font><font size=2>, id);</p> <p align=left>con.Open();</p> <p align=left> </p> <p align=left></p> <p align=left></font><font color="#0000ff" size=2>using</font><font size=2> (</font><font color="#2b91af" size=2>SqlDataReader</font><font size=2> rdr = cmd.ExecuteReader())</p> <p align=left>{</p> <blockquote dir=ltr style="margin-right:0px"> <p align=left></font><font color="#2b91af" size=2>Debug</font><font size=2>.Assert(rdr.RecordsAffected != 1);</font></p> <p align=left><font size=2> </p> <p align=left></font><font color="#008000" size=2>//get the first recrod, we only expect one.</p></font><font size=2> <p align=left>rdr.Read();</p> <p align=left></font><font color="#0000ff" size=2></font> </p> <p align=left><font color="#0000ff" size=2>using</font><font size=2> (</font><font color="#2b91af" size=2>StringReader</font><font size=2> str = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#2b91af" size=2>StringReader</font><font size=2>(</font><font color="#2b91af" size=2>Convert</font><font size=2>.ToString(rdr[</font><font color="#a31515" size=2>&quot;Options&quot;</font><font size=2>])))</p> <p align=left></font><font color="#0000ff" size=2>using</font><font size=2> (</font><font color="#2b91af" size=2>XmlTextReader</font><font size=2> xtr = </font><font color="#0000ff" size=2>new</font><font size=2> </font><font color="#2b91af" size=2>XmlTextReader</font><font size=2>(str))</p> <p align=left>{</p> <blockquote dir=ltr style="margin-right:0px"> <p align=left>xtr.WhitespaceHandling = </font><font color="#2b91af" size=2>WhitespaceHandling</font><font size=2>.Significant;</font></p> <p align=left><font size=2> </p> <p align=left>copt = (</font><font color="#2b91af" size=2>ComparisonOptions</font><font size=2>)xsz.Deserialize(xtr);</p> <p align=left>copt.ID = </font><font color="#2b91af" size=2>Convert</font><font size=2>.ToInt32(rdr[</font><font color="#a31515" size=2>&quot;ID&quot;</font><font size=2>]);</p> <p align=left>copt.Name = </font><font color="#2b91af" size=2>Convert</font><font size=2>.ToString(rdr[</font><font color="#a31515" size=2>&quot;Name&quot;</font><font size=2>]);</p> <p align=left>copt.Description = </font><font color="#2b91af" size=2>Convert</font><font size=2>.ToString(rdr[</font><font color="#a31515" size=2>&quot;Description&quot;</font><font size=2>]);</p></blockquote> <p align=left>}</p></blockquote> <p align=left>}</p></blockquote> <p align=left>}</p></font> <p align=left> </p></div></div> <p align=left> </p></font> <p></p><font size=2></font> <p align=left> </p> <p align=left>Hope that helps, </p> <p align=left>Troy</p>Thu, 03 Apr 2008 23:47:41 Z2008-04-04T11:31:23Zhttp://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/1d3c0ed9-5f26-42b4-a441-b92096aace0a#ed348dad-7e5f-48ea-bad9-e04a9d9411cbhttp://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/1d3c0ed9-5f26-42b4-a441-b92096aace0a#ed348dad-7e5f-48ea-bad9-e04a9d9411cbimran.ahttp://social.msdn.microsoft.com/Profile/en-US/?user=imran.aXMLSerializer \r\n problem<p>Hi Guys,</p> <p align=left> </p> <p align=left>Wrapping the string reader in an xmltextreader seams to have done the trick. When you mentioned 'under the hood' I realised that the <font color="#2b91af">XmlSerializer.Deserialize </font>method itself must be using XMLTextReader under the hood too. Reflector output confirms this. The overide of desirailize I was calling accepts a stream and creates an XMLTextReader with default options that wraps the provided stream. The overload you have suggested using above fixes the problem because we now explicitly specify the XMLTextReader options to use and manually wrap the stream before passing it in. For my particular problem it seems that setting XMLTextReader.Normalization to false does the trick.</p> <p align=left> </p> <p align=left><font face=Arial size=2>Reflector output of <font color="#2b91af">XmlSerializer.Deserialize:</font></font></p> <div class=codeseg> <div class=codecontent> <div class=codesniptitle><span style="width:100%">Code Snippet</span></div> <table style="margin-bottom:0px" cellspacing=0 cellpadding=0 width="100%"> <tbody> <tr> <td style="padding-right:5px;padding-left:5px;padding-bottom:4px;padding-top:4px" valign=top colspan=2><pre><font color="#1000a0">public</font> <a title=System.Object href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Object">object</a> <b><a class=bold href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://System.Xml:2.0.0.0:b77a5c561934e089/System.Xml.Serialization.XmlSerializer/Deserialize(System.IO.Stream):Object">Deserialize</a></b>(<a title=System.IO.Stream href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.IO.Stream">Stream</a> stream) { <a title=System.Xml.XmlTextReader href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://System.Xml:2.0.0.0:b77a5c561934e089/System.Xml.XmlTextReader">XmlTextReader</a> <b>xmlReader</b> = <font color="#1000a0">new</font> <a title="System.Xml.XmlTextReader.XmlTextReader(Stream input);" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://System.Xml:2.0.0.0:b77a5c561934e089/System.Xml.XmlTextReader/.ctor(System.IO.Stream)">XmlTextReader</a>(<a title="Stream stream; // Parameter">stream</a>); <a title="XmlTextReader xmlReader // Local Variable">xmlReader</a>.<a title="WhitespaceHandling System.Xml.XmlTextReader.WhitespaceHandling { ... }" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://System.Xml:2.0.0.0:b77a5c561934e089/System.Xml.XmlTextReader/property:WhitespaceHandling:System.Xml.WhitespaceHandling">WhitespaceHandling</a> = <a title=System.Xml.WhitespaceHandling href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://System.Xml:2.0.0.0:b77a5c561934e089/System.Xml.WhitespaceHandling">WhitespaceHandling</a>.<a title="WhitespaceHandling System.Xml.WhitespaceHandling.Significant;" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://System.Xml:2.0.0.0:b77a5c561934e089/System.Xml.WhitespaceHandling/Significant">Significant</a>; <a title="XmlTextReader xmlReader // Local Variable">xmlReader</a>.<a title="bool System.Xml.XmlTextReader.Normalization { ... }" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://System.Xml:2.0.0.0:b77a5c561934e089/System.Xml.XmlTextReader/property:Normalization:Boolean">Normalization</a> = <font color="#800000">true</font>; <a title="XmlTextReader xmlReader // Local Variable">xmlReader</a>.<a title="XmlResolver System.Xml.XmlTextReader.XmlResolver { ... }" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://System.Xml:2.0.0.0:b77a5c561934e089/System.Xml.XmlTextReader/property:XmlResolver:System.Xml.XmlResolver">XmlResolver</a> = <font color="#800000">null</font>; <font color="#1000a0">return</font> <font color="#1000a0">this</font>.<a title="object System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, string encodingStyle);" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://System.Xml:2.0.0.0:b77a5c561934e089/System.Xml.Serialization.XmlSerializer/Deserialize(System.Xml.XmlReader,String):Object">Deserialize</a>(<a title="XmlTextReader xmlReader // Local Variable">xmlReader</a>, (<a title=System.String href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.String">string</a>) <font color="#800000">null</font>); }</pre></td></tr></tbody></table> <table style="margin-bottom:0px" cellspacing=0 cellpadding=0 width="100%"> <tbody> <tr> <td style="padding-right:5px;padding-left:5px;padding-bottom:4px;padding-top:4px" valign=top colspan=2><pre></pre></td></tr></tbody></table> <p align=left> </p></div></div> <p align=left> </p> <table style="margin-bottom:0px" cellspacing=0 cellpadding=0 width="100%"> <tbody> <tr> <td style="padding-right:5px;padding-left:5px;padding-bottom:4px;padding-top:4px" valign=top colspan=2> <div align=left><pre>Thanks for your help guys.</pre><pre>Imran.</pre></div></td></tr></tbody></table> <table style="margin-bottom:0px" cellspacing=0 cellpadding=0 width="100%"> <tbody> <tr> <td style="padding-right:5px;padding-left:5px;padding-bottom:4px;padding-top:4px" valign=top colspan=2><pre></pre></td></tr></tbody></table>Fri, 04 Apr 2008 11:08:33 Z2008-04-04T11:08:33Zhttp://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/1d3c0ed9-5f26-42b4-a441-b92096aace0a#3aed539b-5008-477a-88ff-1591265bc6b2http://social.msdn.microsoft.com/Forums/en-US/asmxandxml/thread/1d3c0ed9-5f26-42b4-a441-b92096aace0a#3aed539b-5008-477a-88ff-1591265bc6b2John Saundershttp://social.msdn.microsoft.com/Profile/en-US/?user=John%20SaundersXMLSerializer \r\n problem<p>I'm glad you got that working.</p> <p align=left> </p> <p align=left>If this does answer your question, you should mark one of thoward37's responses as an answer.</p> <p align=left><font face=Arial size=2></font> </p>Fri, 04 Apr 2008 11:17:36 Z2008-04-04T11:17:36Z