1

我在 XSD 中定义了以下简单类型:

    <xs:simpleType name="TimeOfDay">
    <xs:annotation>
        <xs:documentation xml:lang="en">The representation of a time value that does not include time zone/offset information.</xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:time">
        <xs:minInclusive value="00:00:00"/>
        <xs:pattern value="(([01][0-9])|(2[0-3]))(:[0-5][0-9]){2}(\.[0-9]+)?"/>
    </xs:restriction>
</xs:simpleType>

当我使用 .NET 4.5 中的 WCF 代码生成功能从中生成 C# 代码时,它会将这种类型映射到 DateTime。因此,当我们将数据协定序列化为 XML 时,该值无法通过模式验证,因为它包含完整的日期/时间值“dd-mm-yyyyThh:mm:ss.fff”。

知道我们如何:

  1. 让生成的代码实现必要的限制
  2. 自定义序列化过程,以便仅将值的时间部分写入 XML 输出
4

0 回答 0