【问题标题】:XML Schema error with restrictions on combining xs:all with an elementXML Schema 错误,限制将 xs:all 与元素组合
【发布时间】:2015-12-05 03:01:36
【问题描述】:

我有一个包含以下内容的架构文件。我收到错误

cos-all-limited.1.2:“所有”模型组必须出现在粒子中 与'{'min发生'}' = '{'max发生'}' = 1,并且该粒子必须 是构成 a 的 '{'content type'}' 的一对的一部分 复杂类型定义。

我该如何解决这个问题?

<?xml version="1.0"?>`enter code here`
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:group name="custGroup">
  <xs:all>
    <xs:element name="customer" type="xs:string"/>
    <xs:element name="orderdetails" type="xs:string"/>
    <xs:element name="billto" type="xs:string"/>
    <xs:element name="shipto" type="xs:string"/>
  </xs:all>
</xs:group>

<xs:element name="order" type="ordertype"/>

<xs:complexType name="ordertype">
<xs:choice>
  <xs:group ref="custGroup"/>
  <xs:element name="status" type="xs:string"/>
  </xs:choice>
</xs:complexType>

</xs:schema>

【问题讨论】:

    标签: xml xsd


    【解决方案1】:

    不要这样使用all,它违反了XSD的确定性原则。您可以通过接受您想要元素的固定顺序(通常是最好的东西)来解决此问题,或者通过将其更改为具有 4..4 序列的 choice 并将每个元素作为自身(全局定义它们以获得此)来解决此问题。

    这是一种方法:

    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    
        <xs:group name="custGroup">
            <xs:sequence>
                <xs:element name="customer" type="xs:string"/>
                <xs:element name="orderdetails" type="xs:string"/>
                <xs:element name="billto" type="xs:string"/>
                <xs:element name="shipto" type="xs:string"/>
            </xs:sequence>
        </xs:group>
    
        <xs:element name="order" type="ordertype"/>
    
        <xs:complexType name="ordertype">
            <xs:choice>
                <xs:element name="status" type="xs:string"/>
                <xs:group ref="custGroup"/>
            </xs:choice>
        </xs:complexType>
    
    </xs:schema>
    

    【讨论】:

    • 使用序列强制执行顺序,这不是我想要的:(
    • @Ananth,在 XSD 中,孩子之间的选择是要么他们都是无序的,要么他们有序。您可以将订单与非订单混合使用(您希望第一个项目被定位,其余的项目是无序的)。 This is a limitation with XSD(不使用 XML)。 RelaxNG(另一种模式方法)没有这个限制
    • @Ananth,因此您可以选择将status 作为xs:all 的一部分,或者您需要手动创建一个具有最小/最大值的选择链,最终与@ 具有相同的效果987654327@,不过也是很多工作。
    • @Ananth,更正,这也行不通,因为您仍然会违反相同的基本原则。如果您这样做,您将收到 [...] 违反“唯一粒子属性”。在针对此架构进行验证期间,将为这两个粒子创建歧义。” 并且不允许歧义,这被称为试图欺骗系统。;)
    • @Ananth: xs:all 在 XSD 中并不像人们预期的那样正交。按照 Abel 的建议,您最好使用 xs:sequence。
    【解决方案2】:

    如果不更改规范,您将无法“解决”它,这不会发生。您可以将内容模型更改为 XSD 支持的模型,也可以使用不同的验证技术。

    【讨论】:

      猜你喜欢
      • 2012-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-03
      • 1970-01-01
      • 2011-12-19
      • 2019-01-13
      相关资源
      最近更新 更多