Schema XSD:元素在节点内唯一,不重复值
问题描述:
我想验证一个XML模式的XML文件,在同一个节点中的值不能重复。签名的顺序很重要。我的无效的XML是:Schema XSD:元素在节点内唯一,不重复值
<person>
<name>Peter Petrelli</name>
<subject1>Mathematics</subject1>
<note1>8.5</note1>
<subject2>Natural Science</subject2>
<note2>4.5</note2>
<subject3>Mathematics</subject3>
<note3>7</note3>
</person>
</school>
这是不可能的数学是不止一次。
我怎样才能验证这与XSD架构?
非常感谢您
答
有了一个更明智的设计不会有什么问题:
<person>
<name>Peter Petrelli</name>
<subject>
<name>Mathematics</name>
<note>2</note>
</subject>
<subject>
<name>Natural Sciences</name>
<note>2.5</note>
</subject>
<subject>
<name>Mathematics</name>
<note>4</note>
</subject>
那么<独特>的<人里面定义>元素可能是:
<unique name="su">
<selector xpath="subject" />
<field xpath="name"/>
</unique>
确实。您使用包含后缀-1,-2,-3等的元素名称似乎使编写明智的XSD模式几乎不可能。它也会对XML进行任何处理(例如使用XSLT或XPath),这些处理将变得非常困难。这是一个非常糟糕的设计。 –
我只写了一个小例子,但是我根据我们的建议改变了我的设计,从现在开始我可以正确验证。非常感谢,伙计们 – rspaz16