Hello,
I have generated classes from xsd and want to serialize the DateTime
.
My class looks like
private System.DateTime timeGMT;
[System.Xml.Serialization.XmlElementAttribute(DataType="time")]
public System.DateTime TimeGMT {
get {
return this.timeGMT;
}
set {
this.timeGMT= value;
}
}
But when I assign any DateTime
object It serializes in format as
<TimeGMT>12:00:00.0000000-04:00</TimeGMT>
But I want it to be serialized as
<TimeGMT>12:00:00</TimeGMT>
I had a look at this question :
http://stackoverflow.com/questions/101533/serializing-datetime-to-time-without-milliseconds-and-gmt
which is similar to my case. But my problem is I also want to validate the generated xml against xsd. So I cannot convert the return type to string. (If I use String as return type then get an exception while generating XML as
time is an invalid value for XMLElementAttribute.DataType property.The property may be specified for only primitive types.
)
Is there any other way out there? Thanks in advance.