[英]Or statement in complex type in xmlschema
How can I define in XMLSchema this pattern of element ? 如何在XMLSchema中定义这种元素模式?
<port num="80"/>
<port min="80" max="443"\\>
because port must be defined by an attribute num or a range . 因为port必须由属性num或range定义。
helderdarocha has already pointed to XSD 1.1. helderdarocha已经指出了XSD 1.1。 Another approach is to re-think your design.
另一种方法是重新考虑您的设计。 It currently uses the same name for two different structures;
它目前对两种不同的结构使用相同的名称; giving them different names makes the problem trivial.
给他们不同的名字使这个问题变得微不足道。
<portnum num="80"/>
<portrange min="80" max="443"/>
or 要么
<port><num>80</num></port>
<port><range min="80" max="443"/></port>
You can achieve that if your parser supports W3C XSD 1.1: 如果您的解析器支持W3C XSD 1.1,您可以实现这一点:
<xs:element name="port" type="portType" />
<xs:complexType name="portType">
<xs:attribute name="min" type="xs:integer" use="optional"/>
<xs:attribute name="max" type="xs:integer" use="optional"/>
<xs:attribute name="num" type="xs:integer" use="optional"/>
<xs:assert test="@num or (@max and @min)" />
</xs:complexType>
If your parser doesn't support XSD 1.1, you can use XSD 1.0 + Schematron, where you place your assertions inside xs:annotation/xs:appinfo
and use XSLT or some external tools to validate them. 如果您的解析器不支持XSD 1.1,您可以使用XSD 1.0 + Schematron,将断言放在
xs:annotation/xs:appinfo
并使用XSLT或一些外部工具来验证它们。 In your case, it might be simpler just to check those assertions in the language that is running your parser after the XSD validation. 在您的情况下,在XSD验证之后检查运行解析器的语言中的断言可能更简单。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.