Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
|
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 12th, 2007, 09:40 PM
Authorized User
 
Join Date: Jun 2005
Posts: 97
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to aldwinenriquez
Default Date serialization problem

I am serializing and deserializing an object and persisting the serialized XML into the database.

My class definition contains a date field.
However I have problems when I try to deserialize the xml back to my defined object. Its complaining that the serialized XML was in invalid format.
Here are my serialization and deserialization codes

public static T GetDeSerializedObj<T>(string strXML)
        {
            StringReader sr = new StringReader(strXML);

            T result = default(T);
            try
            {
                XmlSerializer serializer = new XmlSerializer(typeof(T));
                result = (T)serializer.Deserialize(sr);
            }
            catch (FileNotFoundException)
            {
                result = default(T);
            }
            return result;
        }

        public static string GetSerializedXML<T>(T input)
        {
            StringBuilder sbOutput = new StringBuilder();

            // XmlSerializer serializer = new XmlSerializer(typeof(T));
            XmlSerializer serializer = new XmlSerializer(input.GetType());
            using (StringWriter sw = new StringWriter(sbOutput))
            {
                serializer.Serialize(sw, input);
            }
            return sbOutput.ToString();
        }


Here is the sample XML

<ClassInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <DisplayID>1</DisplayID>
  <ClassID>25</SubmissionID>
  <CreatedTime>1800-01-01T00:00:00</CreatedTime>
  <DateSubmitted>2007-07-13T10:14.9992703+08:00</DateSubmitted>
  <ReceivedMessage />
</ClassInfo>

I noticed that the date submitted value is "2007-07-13T10:14.9992703+08:00" which should be 2007-07-13T10:14:00.9992703+08:00

for it to be a valid XML.

I tried to reproduce it by serializing a ClassInfo object with the seconds timefield set to 0 but I could not reproduce the error.

How is this possible?




"Dont you ever give up!"
__________________
\"Dont you ever give up!\"





Similar Threads
Thread Thread Starter Forum Replies Last Post
serialization taheernawaz ASP.NET 1.x and 2.0 Application Design 0 December 12th, 2007 03:32 AM
Serialization and DeSerialization balesh.mind ASP.NET 2.0 Professional 0 September 12th, 2007 05:05 AM
is serialization required for this? hertendreef ASP.NET 2.0 Basics 0 March 24th, 2007 05:54 AM
question about Serialization hertendreef ASP.NET 2.0 Basics 2 February 27th, 2007 04:03 PM
XML Header serialization problem PMNorris Pro VB.NET 2002/2003 0 January 5th, 2004 07:57 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.