次のシナリオでは:
<apples>
<isred>1</isred>
<color>red</color>
</apples>
いつでなければならないかisred
など、要素の検証に制限を作成する方法はありますか?isred = 1
color
red
編集: ここでは XSD が唯一のオプションです。RelaxNG と Schematron は利用できないオプションです。
次のシナリオでは:
<apples>
<isred>1</isred>
<color>red</color>
</apples>
いつでなければならないかisred
など、要素の検証に制限を作成する方法はありますか?isred = 1
color
red
編集: ここでは XSD が唯一のオプションです。RelaxNG と Schematron は利用できないオプションです。
@ forty-two のポイントでは、これは要件を満たす XSD 1.1 の例です。XSD 1.0 をそのまま使用して、要件に対処するためにできることは何もありません。
<?xml version="1.0" encoding="utf-8"?>
<!--XML Schema generated by QTAssistant/XML Schema Refactoring (XSR) Module (http://www.paschidev.com)-->
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xerces="http://xerces.apache.org">
<xsd:element name="apples">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="isred" type="xsd:unsignedByte"/>
<xsd:element name="color" type="xsd:string"/>
</xsd:sequence>
<xsd:assert test="(isred eq 1 and color eq 'red')" xerces:message="If isred, then color must be red..."/>
</xsd:complexType>
</xsd:element>
</xsd:schema>
無効な例は次のように表示されます。
cvc-assertion.failure: Assertion failed for schema type '#anonymous'. If isred, then color must be red...