【问题标题】:XSD child elements optional/required based on the parent attribute nameXSD 子元素可选/必需,基于父属性名称
【发布时间】:2012-07-26 02:41:00
【问题描述】:

我正在研究 XSD 验证代码,我正在尝试弄清楚如何验证具有

的 XML 文件
<root>
    <elementA attribute1=ID>
    ...
    </elementA>
    <elementA attribute2=ID>
    ...
    </elementA>
</root>

我想制作 XSD,它根据属性名称验证相同的元素,并使 attribute1 的某些子元素可选,而 attribute2 需要。

请注意,“...”是相同的元素,其中某些字段对于 attribute1 是可选的。

【问题讨论】:

    标签: xml xsd


    【解决方案1】:

    在 XSD 1.0 中,元素的类型只能取决于元素名称,而不取决于其属性。 XSD 1.1 使用称为“条件类型分配”的工具消除了这个限制。 XSD 1.1 目前仅在 Xerces 和 Saxon 中实现。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多