加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 22:48:49 所属栏目:百科 来源:网络整理
导读:是否有可能使Relax NG元素/属性独一无二? 例如,属性: rng:attribute name="test" rng:ref name="options"//rng:attribute 参考: rng:define name="options" rng:choice rng:valuet1/rng:value rng:valuet2/rng:value rng:valuet3/rng:value /rng:choice/r
是否有可能使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之间的区别,并且内容模型可以强制它们的唯一性;这不一定是可能的

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读