【问题标题】:XML Schema Validation failing for derived type派生类型的 XML 模式验证失败
【发布时间】:2023-03-11 13:49:01
【问题描述】:

我想知道定义为 XSD simpleType 和以下架构的 XSD 属性的类型是什么,因此验证失败。请看一看,模式验证器工具在“*”分界区域抛出错误,说基本属性类型未正确派生..不确定这是否是正确的定义结构...我周围没有业务模型这个,我只是想在这里玩不同的限制和扩展选项..

    <xsd:complexType name="comptype_simplecontent">
      <xsd:simpleContent>
        <xsd:restriction base="AAA">
            <xsd:attribute name="aaa_attr" *type="xsd:anySimpleType"*></xsd:attribute>
        </xsd:restriction>
      </xsd:simpleContent>
   </xsd:complexType>

   <xsd:complexType name="AAA" block="extension"> 
    <xsd:simpleContent> 
        <xsd:extension base="xsd:integer">
            <xsd:attribute name="aaa_attr">
                <xsd:simpleType>
                    <xsd:restriction base="xsd:decimal">
                        <xsd:minExclusive value="90"></xsd:minExclusive>
                    </xsd:restriction>
                </xsd:simpleType>
            </xsd:attribute>
        </xsd:extension>
    </xsd:simpleContent> 
</xsd:complexType> 

【问题讨论】:

    标签: xml validation schema


    【解决方案1】:

    AAA定义了一个具有整数内容和一个小数属性的复杂类型;一个例子可能是

    <X aaa_attr="93.7">5</X>
    

    您将 comptype_simplecontent 定义为对此的限制,这意味着它允许的元素必须是 AAA 允许的元素的子集。但是在您的限制中,您没有缩小属性中允许的值的范围,而是说它可以采用任何值(anySimpleType)。这是不允许的;受限类型不允许其基类型不允许的事情。

    【讨论】:

    • 我提供的类型“anySimpleType”只是占位符,请填写这个以使架构验证成功......
    • 因为基类型中的属性使用了匿名类型,所以我认为不可能在受限类型中进行限制。
    • is base="xsd:decimal" 不是基本属性“aaa_attr”的类型?
    • 不,属性aaa_attr的类型是一个匿名类型,通过xs:decimal限制派生
    • 我认为这可能是“2.3.1 {base type definition} 不能是·ur-type 定义”的原因......感谢您的回复......
    猜你喜欢
    • 1970-01-01
    • 2018-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-13
    • 2019-06-23
    • 1970-01-01
    相关资源
    最近更新 更多