xml – 放松NG和元素/属性的唯一性

前端之家收集整理的这篇文章主要介绍了xml – 放松NG和元素/属性的唯一性前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
是否有可能使Relax NG元素/属性独一无二?

例如,属性

<rng:attribute name="test">
        <rng:ref name="options"/>
</rng:attribute>

参考:

<rng:define name="options">
    <rng:choice>
        <rng:value>t1</rng:value>
        <rng:value>t2</rng:value>
        <rng:value>t3</rng:value>
    </rng:choice>
</rng:define>

现在我必须验证一个xml,它不应该使用两个“选项”之一.换句话说:在xml中不应该出现两次“t1”……

我读过一些关于schematron的内容.但还有另一种可能性吗?

解决方法

不,Relax NG不支持唯一性约束和参照完整性约束.正如詹姆斯·克拉克在 a paper on the design of Relax NG所说:

The RELAX NG TC spent a considerable amount of time considering what support RELAX NG should provide for enforcing identity (uniqueness and cross-reference) constraints. In the end,the conclusion was that identity constraints were better separated out into a separate specification. Accordingly,RELAX NG itself provides no support for identity constraints.

为了与XML DTD兼容,RelaxNG支持检查ID / IDREF约束.但这是最容易遇到处理器之间的不一致和新用户混淆的领域之一.

你的选择包括

>检查应用程序级别的值的唯一性>使用另一种模式语言(Schematron,DTD,XSD)来制定和实施这种约束(其中,Schematron在实践中最容易使用,作为在特定点补充RelaxNG但是将大部分工作留给RelaxNG的方法)>重新调整XML,以便在元素名称中表示t1,t2和t3之间的区别,并且内容模型可以强制它们的唯一性;这不一定是可能的

猜你在找的XML相关文章