时间类型的.Net XML解析器实现拒绝'24:00:00' [英] .Net XML parser implementation of time type rejects '24:00:00'

查看:67
本文介绍了时间类型的.Net XML解析器实现拒绝'24:00:00'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据XML Schema数据类型规范,值'24:00:00'对于time或dateTime简单类型的时间部分有效,但.Net解析器生成错误 当这个 验证期间在XML文档中遇到值。

According to the XML Schema Datatypes specification a value of '24:00:00' is a valid for the time portion of a time or dateTime simple type but the .Net parser generates an error when this value is encountered in an XML document during validation.

koders网站上XsdDateTime的源代码在parseTime方法中包含以下代码...

The source code for XsdDateTime on the koders website contains the following code in the parseTime method ...

              
if
$
               ;    
Parse2Dig 开始,       ref
小时)&& 小时< 24&&

       ;              
ParseChar start + LzHH ,    ':')&&

                    
Parse2Dig 开始 + LzHH _ ,    ref
分钟
)&& 分钟< 60&&

                   
< a> ParseChar (开始 + LzHH_mm , ':')&&

                   
Parse2Dig 开始 + LzHH_mm_ 参考 )& &安培;
< 60

                ){

               if (
                    Parse2Dig(start ,       ref hour) && hour < 24 &&
                    ParseChar(start + LzHH,     ':') &&
                    Parse2Dig(start + LzHH_,    ref minute) && minute < 60 &&
                    ParseChar(start + LzHH_mm,  ':') &&
                    Parse2Dig(start + LzHH_mm_, ref second) && second < 60
                ) {

...如果小时不是0-23,则导致解析被放弃。它没有尝试检测和处理'24:00:00'的特殊情况。

... which causes the parse to be abandoned of if the hour is not 0-23. It makes no attempt to detect and handle the '24:00:00' special case.

推荐答案

很遗憾,这是System.Xml中的已知限制(请参阅MSDN上的这篇文章,其中提到:
http://msdn.microsoft.com/en-us/library/dd322806(VS.90).aspx

This is unfortunately a known limitation in the System.Xml (See this article on MSDN which mentions this: http://msdn.microsoft.com/en-us/library/dd322806(VS.90).aspx)

根本原因来自.NET DateTime结构。 DateTime.Parse也不接受24:00:00。 XSD规范将此定义为第二天的第一个时刻。现在更不用说弄清楚"第二天"的问题了。确切地说,DateTime
类没有办法存储24:00:00本身。所以我们无法在第二天的24:00:00和00:00:00之间产生影响。因此,如果您尝试再次序列化数据,则与
原始输入相比,输出中会得到不同的值。对于许多人来说,这通常是不可接受的。

The underlying reason comes from the .NET DateTime structure. The DateTime.Parse doesn't accept 24:00:00 either. The XSD spec defines this as the first moment of the next day. Now let alone the problem of figuring out what "next day" exactly means, the DateTime class doesn't have a way to store the 24:00:00 itself. So we could not make a difference between the 24:00:00 and 00:00:00 of the next day. As a result if you would try to serialize the data again, you would get different values in the output compared to the original input. This is usually not acceptable for many people.

问题不仅在于验证,而且还能够为给定的XSD类型转换为.NET存储类型。

The problem is not only about validation but also being able to convert to and from the .NET storage type for the given XSD type.

谢谢,


这篇关于时间类型的.Net XML解析器实现拒绝'24:00:00'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆