You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

xsd:restriction未声明元素属性是否继承父类型?附示例验证

XSD限制(restriction)中元素未声明属性的取值规则及示例解答

核心规则

在XSD的xs:restriction约束中,当子类型重新声明基类型的元素但未指定某一属性时,该属性的取值直接继承自基类型对应元素的属性值,而非使用元素属性的默认值。这是因为restriction的语义是定义基类型的子集,所有未显式修改的属性必须保持基类型的设定,才能确保子类型实例完全符合基类型的校验规则。

针对给定Schema的解答

先看提供的Schema代码:

<xs:complexType name="address">
  <xs:sequence>
    <xs:element name="street" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
  </xs:sequence>
</xs:complexType>

<xs:complexType name="USAddress">
  <xs:complexContent>
    <xs:restriction base="address">
      <xs:sequence>
        <xs:element name="street" type="xs:string" minOccurs="0" />
      </xs:sequence>
    </xs:restriction>
  </xs:complexContent>
</xs:complexType>

基类型address的street元素maxOccurs属性值为unbounded;子类型USAddress在restriction中声明street时仅指定了minOccurs="0",未显式设置maxOccurs。根据上述规则,该属性继承自基类型的设定,因此USAddress的street元素的maxOccurs计算值为unbounded。

内容的提问来源于stack exchange,提问作者Jason Whittle

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 07:43:20