[英]XSD 1.0 set attribute to false if another has no value
I am trying to write a schema where I have two attributes ID
and required
:我正在尝试编写一个模式,其中我有两个属性
ID
和required
:
ID
can be any string or empty string ID
可以是任何字符串或空字符串required
is boolean true/false required
是 boolean 真/假I need to set required
to false if ID
has no text.如果
ID
没有文本,我需要将required
设置为 false。
I searched all over this place and found this can be done using XSD 1.1, but I don't have access to this because its not supported in Visual Studio 2017. Is there an alternative to this in XSD 1.0?我在这个地方进行了搜索,发现这可以使用 XSD 1.1 完成,但我无法访问它,因为它在 Visual Studio 2017 中不受支持。在 XSD 1.0 中是否有替代方法?
This a part of the schema:这是架构的一部分:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="sizeGroup">
<xs:complexType>
<xs:attribute name="ID" type="xs:string" use="required" />
<xs:attribute name="required" type="xs:boolean" use="required" />
</xs:complexType>
</xs:element>
</xs:schema>
XSDs constrain or require properties of XML documents; XSD约束或要求XML 文档的属性; they do not set properties.
他们不设置属性。
Assuming you mean that you wish to require , not set , an attribute to have a certain value based on another attribute's value, no, such a constraint cannot be expressed in XSD 1.0.假设您的意思是您希望,而不是设置,一个属性具有基于另一个属性值的特定值,不,这样的约束不能在XSD 1.0 中表达。 You'll need XSD 1.1 assertions.
您将需要 XSD 1.1 断言。
Note further: Requiring that an attribute value be derived from content already present in another XML component is often a sign of design weakness.进一步注意:要求从另一个 XML 组件中已经存在的内容派生属性值通常是设计缺陷的标志。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.