我需要解决以下问题。
//伪算法
- 你有四个元素:elm1、elm2、elm3、elm4
- elm1 出现 0-2 次li>
- elm2 出现 0-1 次
- elm3 出现 0-n 次
- elm4 出现 0-n 次
- 它们可以以任何方式排序,但只限于给定的数量。
//伪结束
这似乎是顺序和选择的结合,但两个指标都有一个特点,那就是不允许我做出我想要的行为。
样本: 榆树4 榆树1 榆树2 榆树1 榆树3 榆树3 榆树3 榆树4
请在我发疯之前救救我:)
克里斯
最佳答案
如果您的 n
值不太大并且您很绝望,您可以制作一个内容模型来解释所有可能的组合,但它会呈指数级增长。
最好的解决方案是使用支持 XML Schema 1.1 的工具(例如 Xerces 或 Saxon ),它放宽了对所有
组出现值的限制。来自 section G.1.3规范的:
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.
如果做不到这一点,一般的 XML Schema 1.0 解决方案是在模式中指定一个宽松的模型(对元素出现次数没有限制),然后在另一层强制执行您关心的约束,这可能是自定义代码或 XSLT,因为实例。
关于xml - 是否可以将元素限制为最大出现在 "choice" block 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5089730/