【问题标题】:xsd empty string validationxsd 空字符串验证
【发布时间】:2019-11-03 02:17:28
【问题描述】:

基于该 xsd 架构:

<xs:simpleType name="TextType">
    <xs:restriction base="xs:string">
        <xs:minLength value="1"/>
        <xs:maxLength value="50"/>
    </xs:restriction>
</xs:simpleType>
...
<xs:element maxOccurs="10" minOccurs="0" name="MyText" type="TextType"/>

这样的空白值是否应该有效?为什么?

<MyText>  </MyText>

【问题讨论】:

    标签: xml xsd xsd-validation xml-validation


    【解决方案1】:

    是的,它是有效的。该值可以是长度在 1-50 个字符之间的任何字符串,这是一个长度介于这些限制之间的字符串。

    如果您想在应用长度检查之前消除空格,您可以考虑使用xs:whiteSpace facet,或使用派生类型,例如xs:token

    【讨论】:

    • 好的,我明白了。这与This string datatype is the only predefined datatype for which no whitespace replacement is performed link ?
    • 使用 .Net XMLReader 时,此方案的架构验证失败。根据您所说,架构验证应该通过,对吗?
    • 是的,应该。但是有很多细节表明 Microsoft XSD 实现不太符合 W3C 规范。
    猜你喜欢
    • 2013-07-30
    • 1970-01-01
    • 2014-05-08
    • 1970-01-01
    • 1970-01-01
    • 2012-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多