XSD中禁止原始数据类型的空元素 [英] Empty elements for primitve datatypes forbidden in XSD
问题描述
我在处理Web服务响应时遇到了Apache CXF解析错误。归结为返回了一个空元素:
I encountered a parsing error with Apache CXF while processing a webservice response. What it comes down to is an empty element being returned:
<myValue />
元素定义如下:
<xsd:element name="myValue" type="xsd:float" minOccurs="0">
现在我在CXF邮件列表中看到 XSD规范不允许使用空值:
Now I've read on the CXF mailing list that an empty value is not allowed by the XSD-spec:
嗯,
没有解决方法,因为它不是错误。空的
元素对于任何Decimal
或Date类型或类似的内容均无效。
因此,它应该引发异常。
您是什么
Well, there isn't a workaround for this as it's not a bug. An empty element is not valid for any Decimal or Date type or anything like that.
Thus, it SHOULD throw an exception.
What are you expecting it to do?
现在出现了问题:在XML Schema规范中我在哪里可以找到这个约束?
Now here comes the question: Where exactly can I find this constraint in the XML Schema specification?
推荐答案
在XML Schema规范中哪里可以找到此约束?
Where exactly can I find this constraint in the XML Schema specification?
http ://www.w3.org/TR/xmlschema-2/#float-lexical-representation
浮点值具有由
尾数组成的词法
表示形式,其后是
字符 E或 e,然后是
指数。
...
指数和
尾数的表示形式必须遵循词法规则
的整数和十进制。
...
特殊值正数和
负无穷大且非数字
具有词法表示INF,-INF
和NaN。
float values have a lexical representation consisting of a mantissa followed, optionally, by the character "E" or "e", followed by an exponent.
...
The representations for exponent and mantissa must follow the lexical rules for integer and decimal.
...
The special values positive and negative infinity and not-a-number have lexical representations INF, -INF and NaN, respectively.
所以 xs:float
至少需要a尾数是 xs:decimal
...
So xs:float
requires at least a mantissa that is a xs:decimal
...
小数具有词法表示形式
由十进制数的有限长度序列
(#x30-#x39)
组成,中间用句点分隔,作为十进制
指示符。可选的前导符号允许
。
decimal has a lexical representation consisting of a finite-length sequence of decimal digits (#x30-#x39) separated by a period as a decimal indicator. An optional leading sign is allowed.
...并且空字符串不是有效的 xs:decimal
。
...and an empty string is not a valid xs:decimal
.
如果没有该元素的值,则应尽可能不包括此元素。您的架构似乎允许省略该元素,因为 minOccurs
的值是 0
。其他解决方案是插入合适的替换值,例如 0
或 NaN
。
If you don't have a value for this element, you should try not including this element, if possible. Your schema seems to allow omitting this element because minOccurs
has value 0
. Other solution would be to insert a suitable replacement value, like 0
or NaN
.
这篇关于XSD中禁止原始数据类型的空元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!