我希望创建一个XML文档,其中的一个元素必须使用两个已知属性之一来定义,但不能同时使用这两个属性。XSD:A <xs:choice>等同于属性
例如,我想定义一个“webAddress”元素如下:
<xs:element name="webAddress">
<xs:complexType>
<xs:attribute name="hostName" type="xs:string"/>
<xs:attribute name="hostAddress" type="xs:string"/>
</xs:complexType>
</xs:element>
但我只希望用户能够定义一个主机名的属性(例如,主机名=“)或一个hostAddress(例如,hostAddress =“”)属性,但不能同时存在,看起来该构造完成了这个元素,是否有属性的功能等价物,或者是否有更好的方法来处理这个属性?
如果找到我们不能使用W3C XML Schema来做到这一点 我们可以使用嵌入式schematron规则,但是我们可以在选择元素上做到这一点通过检查元素和属性在一起? 例如是这样的:
<xs:choice>
<xs:element name="webAddress">
<xs:complexType>
<xs:attribute name="hostName" type="xs:string"/>
</xs:complexType>
</xs:element>
<xs:element name="webAddress">
<xs:complexType>
<xs:attribute name="hostAddress" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:choice>
进一步你可以使属性为强制使用=“required” – Naren
这不完全是我想看到的。 'hostName'和'hostAddress'应该具有相同的权利 – Nick
相同的权利意味着? – Naren