XSD 类型仅允许属性或内容,但不能同时允许两者
我正在尝试创建一个 XSD 内容类型,该类型允许属性或内容,但不能同时允许两者(或两者都不允许)。例如,以下内容是允许的:
<data cid="my_id" />
<data>TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGh</data>
但以下内容是不允许的:
<data cid="my_id">TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGh</data>
<data />
到目前为止,我对此所做的最佳尝试允许两者之一,但也允许两者/两者都不。
<xs:complexType name="data">
<xs:simpleContent>
<xs:extension base="xs:base64Binary">
<xs:attribute name="cid" type="xs:string" use="optional" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
I am trying to make an XSD content-type that allows either an attribute or content, but not both simultaneously (or neither). For example, the following would be allowed:
<data cid="my_id" />
<data>TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGh</data>
But the following would not be allowed:
<data cid="my_id">TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGh</data>
<data />
The best attempt I have for this so far allows either but also both/neither.
<xs:complexType name="data">
<xs:simpleContent>
<xs:extension base="xs:base64Binary">
<xs:attribute name="cid" type="xs:string" use="optional" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,这对于 XSD 1.0 来说是不可能的。有了这些要求,您最终将不得不从 XSD 之上的另一种模式语言获得帮助,例如 Schematron。 XSD 1.1 将允许您断言规则以达到您需要的效果;不幸的是,目前对 XSD 1.1 的支持相当有限。
Unfortunately, this is not possible with XSD 1.0. With these requriements, you would have to get help from another schema language, on top of XSD eventually, such as Schematron. XSD 1.1 would allow you to assert a rule to the effect you need; unfortunately, support for XSD 1.1 is quite limited at this time.