I have a class that was auto-generated by the XSD tool in visual studio 2008; this class looks like this:
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://www.xxx.com")]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "http://www.xxx.com", IsNullable = false)]
public partial class Invoice
{
private DateTime startDateField;
// Some other fields goes here.
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public System.DateTime startDate
{
get
{
return this. startDateField;
}
set
{
this. startDateField = value;
}
}
}
When I serialize an instance of Invoice I get an xml that looks like this:
<?xml version="1.0" encoding="utf-8"?>
<Invoice xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.xxx.com http://www.xxx/cfdv22.xsd" startDate ="2012-09-27T16:41:36-07:00">
… some other elements goes here.
</Invoice>
If you see the value of the attribute startDate contains the time zone at the end.
Is there any way to speficify something during the realization that converts the datetime object to its representation like this yyyy-MM-ddTHH:mm:ss? Or something that removes the time zone?
Thanks in advance.
The “datetime” type in XML is an ISO8601 date, as per the XML Schema Recomendation.
If you don’t care for the timezone, then the “date” datatype is probably what you want.