我试图使两个XML属性相互排斥.如何创建XSD模式来捕获这种场景?
我想要有一个
<elem value="1" /> <elem ref="something else" />
但不是
<elem value="1" ref="something else" />
由于在Alnitak的答案中提到了
RelaxNG,这里是一个解决方案
与RelaxNG(一种在大多数情况下比W3C更好的语言)
架构).在elem的定义中记下OR(|):
原文链接:https://www.f2er.com/xml/292920.html与RelaxNG(一种在大多数情况下比W3C更好的语言)
架构).在elem的定义中记下OR(|):
start = document document = element document {elem+} elem = element elem {ref | value} ref = attribute ref {text} value = attribute value {xsd:integer}
如果我有这个XML文件:
<document> <elem value="1" /> <elem ref="something else" /> </document>
% rnv attributes-exclusive.rnc attributes-exclusive.xml attributes-exclusive.xml % xmllint --noout --relaxng attributes-exclusive.rng attributes-exclusive.xml attributes-exclusive.xml validates
<elem value="1" ref="something else" />
% rnv attributes-exclusive.rnc attributes-exclusive.xml attributes-exclusive.xml attributes-exclusive.xml:4:0: error: attribute ^ref not allowed required: after % xmllint --noout --relaxng attributes-exclusive.rng attributes-exclusive.xml attributes-exclusive.xml:4: element elem: Relax-NG validity error : Invalid attribute value for element elem attributes-exclusive.xml fails to validate