④XMLスキーマで選択値の定義
XMLスキーマで、選択値をチェックしてみます。
簡単なサンプルを作ってみます。
■SelectValue.xml
<?xml version="1.0" encoding="UTF-8"?> <greeting xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="SelectValue.xsd" attribute="Hello World!!">Hello World!!</greeting>
■SelectValue.xsd
<?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="greeting" type="greetingType" /> <xsd:complexType name="greetingType"> <xsd:simpleContent> <xsd:extension base="greetingString"> <xsd:attribute name="attribute" type="greetingString" use="required" /> </xsd:extension> </xsd:simpleContent> </xsd:complexType> <xsd:simpleType name="greetingString"> <xsd:restriction base="xsd:string"> <xsd:enumeration value="Hello World!!" /> <xsd:enumeration value="HELLO WORLD!!" /> </xsd:restriction> </xsd:simpleType> </xsd:schema>
「greetingString」型を選択値にしました。
選択値は、「
「
… <xsd:enumeration value="Hello World!!" /> <xsd:enumeration value="HELLO WORLD!!" /> …
Eclipseで、XMLスキーマ検証してみます。
「StringPattern.xml」を開いて、右クリックメニューの「検証」で、XMLスキーマ検証します。
エラーは出ませんね。
SelectValue.xmlの
■SelectValue.xml
<?xml version="1.0" encoding="UTF-8"?> <greeting xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="SelectValue.xsd" attribute="Hello World!!123">HELLO WORLD!!</greeting>
「SelectValue.xsd」では、