【问题标题】:complexContent restriction: is it XSD 1.0 or Xerces causing this behavior change?complexContent 限制:是 XSD 1.0 还是 Xerces 导致了这种行为变化?
【发布时间】:2021-11-12 18:08:59
【问题描述】:

这是一个小架构和一个示例 XML 文件,如果选择 XSD 1.1 版而不是 XSD 1.0,它将在 Xerces-J online validation service 成功验证。

选择 1.0 时,架构本身被拒绝,因为从 t1 派生 t2 无效。 (意图是t1 允许可选的thing 和一些stuff,而t2 是保留stuff 但禁止thing 的限制。)

选择 1.0 的 Xerces-J 的确切投诉是:

[Error] foo.xsd:19:28:rcase-Recurse.1: Group's occurrence range, (0,unbounded), is not a valid restriction of base group's occurrence range, (1,1).
[Error] foo.xsd:19:28:derivation-ok-restriction.5.4.2: Error for type 't2'. The particle of the type is not a valid restriction of the particle of the base.

认为发生的情况是 t2 中包含的 <sequence> 被认为是“无意义的”(2.2.2.2.1 here),因为它现在只有一个孩子,但对应的t1 中的 <sequence> 不是“毫无意义的”,因为它有两个孩子,并且派生检查器试图将 t2<group>minOccursmaxOccurst1t1 匹配年代<sequence>。不知何故,XSD 1.1 的检查器比这更聪明。

所以我的问题(好的,两个问题):

  • 1.0 中的这种行为是 XSD 1.0 的固有已知限制,1.1 中的派生规则已更新以修复,还是 1.0 的 Xerces-J 实现 的限制?有人有接受此架构的 1.0 实现吗?

  • 鉴于使用 1.0 的工具的持续部署,是否有人知道编写此架构的另一种方法可以在 1.0 中使用? (我可以通过丢失<group> 并内联<stuff> 元素来使这个示例工作,但如果现实生活中的组有多个孩子,这不是一个计划。

编辑:如果元素领导一个替换组,即使内联解决方法也无效。这被具体化为here<choice> 组,它的minOccursmaxOccurs 与基本类型的<sequence> 不匹配。

foo.xsd:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
 elementFormDefault="qualified"
 targetNamespace="foo:bar"
 xmlns="foo:bar">

 <xs:group name="stuffGroup">
  <xs:sequence>
   <xs:element name="stuff"/>
  </xs:sequence>
 </xs:group>

 <xs:complexType name="t1">
  <xs:sequence>
   <xs:element name="thing" minOccurs="0"/>
   <xs:group ref="stuffGroup" minOccurs="0" maxOccurs="unbounded"/>
  </xs:sequence>
 </xs:complexType>

 <xs:complexType name="t2">
  <xs:complexContent>
   <xs:restriction base="t1">
    <xs:sequence>
     <xs:group ref="stuffGroup" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
   </xs:restriction>
  </xs:complexContent>
 </xs:complexType>

 <xs:element name="a" type="t2"/>

</xs:schema>

foo.xml:

<a xmlns='foo:bar'/>

【问题讨论】:

    标签: xsd xerces


    【解决方案1】:

    基于 Microsoft .NET XSD 1.0 的架构验证器拒绝您的架构,并在第 19 行显示错误(首先引用我从 VS 获得的德语消息):“ Warnung Ungültige Partikelableitung durch Einschränkung - 'Gemäß All:All,Sequence:Sequence -- Recurse-Regel 1 oder Choice:Choice -- RecurseLax ist der Bereich des abgeleiteten Partikels keine gültige Einschränkung des Basispartikelbereichs.'。通过限制警告无效粒子推断 - 根据 All:All,Sequence:Sequence -- Recurse-rule 1 oder Choice:Choice -- RecurseLax 是推断粒子的域,没有对基本粒子域的有效限制。

    Xmllint(“xmllint:使用 libxml 版本 20910”),另一方面,当尝试使用例如模式验证样本时命令行选项--schema schema1.xsd sample1.xml 报告:

    <?xml version="1.0"?>
    <a xmlns="foo:bar"/>
    sample1.xml validates
    

    我需要更深入地挖掘架构规范以判断什么是正确的行为。

    【讨论】:

    • 感谢您的检查。
    • 当我在 t1 中添加第三个孩子并将其保留在 t2 中,以便 t2 的序列有多个孩子时,问题就消失了。所以我认为它确实忽略了“毫无意义”的序列,即使这会导致推导失败。这可能是对规范“任何毫无意义的事件......都被忽略”的公平解读,它可能应该被表述为“如果推导成功则可能被忽略”。
    猜你喜欢
    • 1970-01-01
    • 2011-09-30
    • 1970-01-01
    • 1970-01-01
    • 2011-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多