独特的粒子属性 - XSD 问题

Unique Particle Attribution - XSD issue

我动态地从 MQ 收到其中任何一个 XML。 所有元素应按相同顺序排列且均为必填字段。

<?xml version="1.0" encoding="UTF-8"?>
<ABC xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <IDEN>
   <A>A</A>
   <B>B</B>
   <C>C</C>
  </IDEN>
</ABC>

<?xml version="1.0" encoding="UTF-8"?>
<ABC xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <IDEN>
   <A>A</A>
   <BB>BB</BB>
   <C>C</C>
  </IDEN>
</ABC>

XSD :

<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="ABC">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="IDEN">
          <xs:complexType>
            <xs:choice>
                <xs:sequence>
                  <xs:element type="xs:string" name="A"/>
                  <xs:element type="xs:string" name="B"/>
                  <xs:element type="xs:string" name="C"/>
                </xs:sequence>
                <xs:sequence>
                  <xs:element type="xs:string" name="A"/>
                  <xs:element type="xs:string" name="BB"/>
                  <xs:element type="xs:string" name="C"/>
                </xs:sequence>
            </xs:choice>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

也尝试过

错误:

Cos-nonambig: A And A (or Elements From Their Substitution Group) Violate "Unique Particle Attribution". During Validation Against This Schema, Ambiguity Would Be Created For Those Two Particles

我知道很多人早些时候遇到过同样的问题,但是 none 他们的解决方案对我有所帮助。请提出建议。

问题是由于序列之间的共同元素。第二个序列的不同之处仅在于它的中间元素,此时只有解析器可以识别模式定义。在完全解析序列之前,无法区分公共元素(<A/><C/>)。模式验证是逐个元素完成的。相反,解析器必须延迟验证,直到遇到第二个元素。我不相信这是解析器的工作方式。相反,我的建议是:

<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="ABC">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="IDEN">
          <xs:complexType>
            <xs:sequence>
              <xs:element type="xs:string" name="A"/>
              <xs:choice>
                <xs:element type="xs:string" name="B"/>
                <xs:element type="xs:string" name="BB"/>
              </xs:choice>
              <xs:element type="xs:string" name="C"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

简而言之,解析器应该以确定的方式知道何时在元素 上来自元素本身 ,而不是从后续元素中使用什么模式组件进行验证。