I
Ivan A.
Hi!
Why I can't serialize TimeSpan structure with XmlSerializer? This is what I
do:
using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
namespace ConsoleApplication1
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class Class1
{
public TimeSpan span = new TimeSpan(1, 2, 3);
public DateTime time = new DateTime(1, 1, 1, 1, 1, 1, 1);
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
XmlSerializer serializer = new XmlSerializer(typeof(Class1));
XmlTextWriter xmlwriter = new XmlTextWriter("c:\\testser.xml",
System.Text.Encoding.Unicode);
Class1 c = new Class1();
c.span = new TimeSpan(3, 2, 1);
serializer.Serialize(xmlwriter, c);
xmlwriter.Close();
}
}
}
And this is what I get::
<?xml version="1.0" encoding="utf-16" ?>
- <Class1 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<span />
<time>0001-01-01T01:01:01.0010000+02:00</time>
</Class1>
Why I can't serialize TimeSpan structure with XmlSerializer? This is what I
do:
using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
namespace ConsoleApplication1
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class Class1
{
public TimeSpan span = new TimeSpan(1, 2, 3);
public DateTime time = new DateTime(1, 1, 1, 1, 1, 1, 1);
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
XmlSerializer serializer = new XmlSerializer(typeof(Class1));
XmlTextWriter xmlwriter = new XmlTextWriter("c:\\testser.xml",
System.Text.Encoding.Unicode);
Class1 c = new Class1();
c.span = new TimeSpan(3, 2, 1);
serializer.Serialize(xmlwriter, c);
xmlwriter.Close();
}
}
}
And this is what I get::
<?xml version="1.0" encoding="utf-16" ?>
- <Class1 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<span />
<time>0001-01-01T01:01:01.0010000+02:00</time>
</Class1>