问题描述
我已经使用XSD文件作为输入创建一个C#类文件。我的一个特性是这样的:
I have created a C# class file by using a XSD-file as an input. One of my properties look like this:
private System.DateTime timeField;
[System.Xml.Serialization.XmlElementAttribute(DataType="time")]
public System.DateTime Time {
get {
return this.timeField;
}
set {
this.timeField = value;
}
}
在序列化,该文件的内容现在看起来是这样的:
When serialized, the contents of the file now looks like this:
<Time>14:04:02.1661975+02:00</Time>
是否有可能,有对物业XMLATTRIBUTES,有它使没有毫秒,格林尼治标准时间值也是这样吗?
Is it possible, with XmlAttributes on the property, to have it render without the milliseconds and the GMT-value like this?
<Time>14:04:02</Time>
这是可能的,或者我需要破解在一起某种XSL / XPath的替换魔术类已系列化后?
Is this possible, or do i need to hack together some sort of xsl/xpath-replace-magic after the class has been serialized?
有不是解决改变对象到字符串,因为它用于像在应用程序的其余部分DateTime和允许我们通过使用XmlSerializer.Serialize创建从对象一个xml-重新presentation ()方法。
It is not a solution to changing the object to String, because it is used like a DateTime in the rest of the application and allows us to create an xml-representation from an object by using the XmlSerializer.Serialize() method.
我需要从外地删除多余信息的原因是接收系统不符合W3C标准的标准时间数据类型。
The reason I need to remove the extra info from the field is that the receiving system does not conform to the w3c-standards for the time datatype.
推荐答案
您可以创建一个字符串属性,做翻译到/从你的timeField领域,并把序列化的属性上而不是真实的日期时间属性,其余应用程序使用。
You could create a string property that does the translation to/from your timeField field and put the serialization attribute on that instead the the real DateTime property that the rest of the application uses.
这篇关于序列化的DateTime,恕不毫秒,格林尼治标准时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!