【问题标题】:XML Schema: what is the benefit of a restriction based on xs:anyTypeXML Schema:基于 xs:anyType 的限制有什么好处
【发布时间】:2015-10-06 10:09:52
【问题描述】:

在一个项目中,我们必须连接到一个 web 服务,该服务在其 wsdl 中定义了许多基于 xs:anyType 限制的类型,如下所示:

<xs:schema  xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xs:element name="myElement" type="myTypeDef" />

    <xs:complexType name="myTypeDef">
          <xs:complexContent>
              <xs:restriction base="xs:anyType">
                  <xs:sequence>
                      <xs:element name="elementOne" type="xs:string"/>
                      <xs:element name="elementTwo" type="xs:string"/>
                  </xs:sequence>
              </xs:restriction>
          </xs:complexContent>
    </xs:complexType>

</xs:schema>

与像

这样的普通类型定义有什么区别
    <xs:complexType name="myTypeDefPlain">
        <xs:sequence>
            <xs:element name="elementOne" type="xs:string"/>
            <xs:element name="elementTwo" type="xs:string"/>
        </xs:sequence>
    </xs:complexType>

据我了解,这两种类型定义是相同的。真的吗?有没有使用基于 xs:anyType 的限制的用例?

【问题讨论】:

    标签: jakarta-ee xsd wsdl


    【解决方案1】:

    在这种情况下,没有。检查the spec, §3.4.2,特别是例子:

    <xs:complexType name="length2">
     <xs:complexContent>
      <xs:restriction base="xs:anyType">
       <xs:sequence>
        <xs:element name="size" type="xs:nonNegativeInteger"/>
        <xs:element name="unit" type="xs:NMTOKEN"/>
       </xs:sequence>
      </xs:restriction>
     </xs:complexContent>
    </xs:complexType>
    
    <xs:complexType name="length3">
     <xs:sequence>
      <xs:element name="size" type="xs:nonNegativeInteger"/>
      <xs:element name="unit" type="xs:NMTOKEN"/>
     </xs:sequence>
    </xs:complexType>
    

    length3 是 length2 的缩写:它们对应于 相同的类型定义组件

    【讨论】:

      猜你喜欢
      • 2010-12-25
      • 1970-01-01
      • 2021-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多