是否可以将元素限制为“选择"中出现的最大值?堵塞? [英] Is it possible to restrict elements to a max occur in a "choice" block?

查看:23
本文介绍了是否可以将元素限制为“选择"中出现的最大值?堵塞?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要解决以下问题.

//伪算法

  • 你有四个元素:elm1、elm2、elm3、elm4
  • elm1 出现 0-2 次
  • elm2 出现 0-1 次
  • elm3 出现 0-n 次
  • elm4 出现 0-n 次
  • 它们可以以任何方式排序,但仅限于给定的数量.

//伪结束

这似乎是顺序和选择的组合,但两个指标都有一个特征,即不允许我出现我想要的行为.

示例:榆木4榆树1榆树2榆树1榆树3榆树3榆树3榆木4

请在我发疯之前救我:)

克里斯

解决方案

如果您的 n 值不是太大并且您很绝望,您可以制作一个考虑到所有可能组合的内容模型,但是呈指数级增长.

最好的解决方案是使用支持 XML Schema 1.1 的工具(例如 XercesSaxon),它放宽了对 all 组出现值的限制.来自规范的第 G.1.3 节:

<块引用>

  1. 本规范 1.0 版强加的几个限制所有组都放宽了:

    一个.现在允许通配符组.

    B.maxOccurs 的值现在可能是在所有粒子上大于 1团体.匹配的元素特定粒子不必是在输入中相邻.

    c.现在可以通过以下方式扩展所有组向他们添加更多成员.

如果做不到这一点,一般的 XML Schema 1.0 解决方案是在模式中指定一个宽松的模型(对元素出现没有限制),然后在另一层(可能是自定义代码或 XSLT)中强制执行您关心的约束,例如实例.

I need to solve the following problem.

//pseudo algorithm

  • you have four elements: elm1, elm2, elm3, elm4
  • elm1 occurs 0-2 times
  • elm2 occurs 0-1 times
  • elm3 occurs 0-n times
  • elm4 occurs 0-n times
  • they can be ordered in any way, but occur restricted to their given count.

//pseudo end

It seems like a combination of sequence and choice, but both indicators have a characteristic, that don't allow me my desired behavior.

sample: elm4 elm1 elm2 elm1 elm3 elm3 elm3 elm4

please rescue me before I'll get insane :)

chris

解决方案

If your n values not too big and you're desperate you can make a content model that accounted for every possible combination, but that grows complex exponentially.

The best solution is to use a tool that supports XML Schema 1.1 (such as Xerces or Saxon), which relaxes restrictions on all group occurrence values. From section G.1.3 of the spec:

  1. Several of the constraints imposed by version 1.0 of this specification on all-groups have been relaxed:

    a. Wildcards are now allowed in all groups.

    b. The value of maxOccurs may now be greater than 1 on particles in an all group. The elements which match a particular particle need not be adjacent in the input.

    c. all groups can now be extended by adding more members to them.

Failing that, the general XML Schema 1.0 solution is to specify a relaxed model in the schema (no limits on the element occurrences) and then enforce the constraints you care about in another layer, which might be custom code or XSLT, for instance.

这篇关于是否可以将元素限制为“选择"中出现的最大值?堵塞?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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