我使用XSD文件作为输入创建了一个C#类文件.我的一个属性看起来像这样:
private System.DateTime timeField;
[System.Xml.Serialization.XmlElementAttribute(DataType="time")]
public System.DateTime Time {
get {
return this.timeField;
}
set {
this.timeField = value;
}
}
Run Code Online (Sandbox Code Playgroud)
序列化时,文件的内容现在如下所示:
<Time>14:04:02.1661975+02:00</Time>
Run Code Online (Sandbox Code Playgroud)
在属性上使用XmlAttributes,是否有可能在没有毫秒和GMT值的情况下渲染它?
<Time>14:04:02</Time>
Run Code Online (Sandbox Code Playgroud)
这是可能的,还是我需要在序列化类之后将某种xsl/xpath-replace-magic混合在一起?
它不是将对象更改为String的解决方案,因为它在应用程序的其余部分中像DateTime一样使用,并允许我们使用XmlSerializer.Serialize()方法从对象创建xml表示.
我需要从字段中删除额外信息的原因是接收系统不符合time数据类型的w3c标准.