一个 XML 模式枚举可以扩展另一个 XML 模式枚举吗?
我希望我的 XML 模式包含两个字符串枚举,一个扩展另一个:
- 枚举 1:狗,猫
- 枚举 2(将“蛇”添加到第一个):狗,猫,蛇
我尝试过 union,但结果类型至少看起来不是枚举它不被 xAmple 识别。
有没有一种方法可以让一个枚举扩展另一个枚举并且仍然是一个枚举?
I'd like my XML schema to contain two string enumerations, one that extends the other:
- Enumeration 1: dog, cat
- Enumeration 2 (adds "snake" to the first): dog, cat, snake
I've tried a union, but the resulting type doesn't seem to be an enumeration, at least it's not recognised by xAmple as such.
Is there a way to have one enumeration extend another and still be an enumeration?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简单类型只能通过限制而不是通过扩展来派生。 (联合很特殊,被认为是
anySimpleType
的限制。)如果您只是想避免重复(而不是定义层次结构),那么联合应该适合验证,尽管有些情况并不奇怪。工具不会研究工会来做一些聪明的事情。
另一种选择是定义所有值(狗、猫、蛇)的基类型,然后派生一个仅包含子集的类。这为您提供了一个层次结构,但派生类必须重复子集(狗、猫)或通过正则表达式禁止其他子集(蛇)。 (使用正则表达式可能也会让许多编辑者陷入困境。)
Simple types can only be derived by restriction and not by extension. (Unions are special and considered to be restrictions of
anySimpleType
.)If you're just trying to avoid duplication (rather than define a hierarchy) then union should be fine for validation, though it's not surprising that some tools won't look into the union to do something smart.
Another option is to define a base type will all values (dog, cat, snake) and then derive a class that only contains the subset. That gives you a hierarchy but the derived class must either repeat the subset (dog, cat) or disallow the others (snake) by regex. (And using the regex will probably also trip up many editors.)