XSD:根据前一个属性的值定义属性 [英] XSD: Define attributes based on the value of previous attribute

查看:35
本文介绍了XSD:根据前一个属性的值定义属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我猜这个功能不存在,但我想我会试一试.

I'm going to guess that this functionality doesn't exist, but I thought I'd give it one last shot.

我有一个要验证的 XML 结构(我无法控制此结构).

I've got an XML structure I'm trying to validate (I have no control over this structure).

在这个结构中,我可以有多个条件"标签,每个标签都有一个属性类型",然后该标签中的其余属性取决于该类型是什么.因此,例如,如果它看起来像这样:

In this structure I can have multiple "Condition" tags, each tag has an attribute "type" and then the remaining attributes in that tag is dependent on what that type is. So if for example it looked like so:

<Condition type="LessThan" maxAmount="3">
   <Effect type="Add" value="2" />
</Condition>
<Condition type="GreaterThan" minAmount="1">
   <Effect type="Transform" action="Skew" value="4"  />
   <Effect type="Transform" action="Stretch" value="3" />
</Condition>
<Condition type="Range" minAmount="1" maxAmount="3">
   <Effect type="YouGetTheDrift" />
</Condition>

那么如果它是 LessThan 类型,它只需要一个 maxAmount 标签等

Then if it's type LessThan, it only needs a maxAmount tag, etc.

没有办法根据前一个属性的值来使属性成为必需/可选/禁止,嘿?

There is no way to make attributes required/optional/prohibited base on the value of a previous attribute, hey?

我尝试使用多个条件标签创建一个选择,每个类型都有固定的类型值和自定义属性集,但它抱怨标签具有相同的名称.

I tried to create a choice with multiple Condition tags, with fixed values of type and custom attribute sets per type, but it complained about the tags having the same name.

推荐答案

您描述的功能的名称是共现约束",它们在 XSD 1.0 中不受支持.

The name for the feature you are describing is "co-occurrence constraints", and they aren't supported in XSD 1.0.

您可以使用条件类型分配"语法在 XSD 1.1 中执行此操作,其中元素的类型取决于其属性的值;你也可以使用断言来做到这一点.XSD 1.1 现在是最终的 W3C 推荐标准,并在 Xerces 和 Saxon 中实现.

You can do this in XSD 1.1 using the "conditional type assignment" syntax, where the type of an element depends on the values of its attributes; you can also do it using assertions. XSD 1.1 is now a final W3C Recommendation and is implemented in Xerces and Saxon.

这篇关于XSD:根据前一个属性的值定义属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆