以下の xsd を以下の xml ファイルに対してテストしようとすると問題が発生します。ツールが悪いのでしょうか、それとも xsd が予測どおりに機能していないのでしょうか?
テスト済みのソフトウェア:
- xmllint (libxml バージョン 20707 を使用)
- XML コピー エディター 1.2.0.6
予想された結果:
- test.xml は検証します
- ドメインタグのアカウント属性の形式が正しくないため、test-bad.xml は検証に失敗します
観察結果: - test.xml の検証 - test-bad.xml の検証
test.xml
<?xml version="1.0" ?>
<!DOCTYPE configuration SYSTEM "configuration.dtd">
<configuration timestamp="2011-03-23T20:16:57.222" version="2.2" xmlns="http://www.example.com/api/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.com/api/2.2 configuration.xsd">
<domain account="4af17ss66f-c841-4b97-a94a-edd7a012176" >
</domain>
</configuration>
test-bad.xml
<?xml version="1.0" ?>
<!DOCTYPE configuration SYSTEM "configuration.dtd">
<configuration timestamp="2011-03-23T20:16:57.222" version="2.2" xmlns="http://www.example.com/api/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.com/api/2.2 configuration.xsd">
<domain account="totally invalid account" >
</domain>
</configuration>
構成.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.example.com/api/2.2" elementFormDefault="qualified" version="1.0" xml:lang="EN" targetNamespace="http://www.example.com/api/2.2">
<xs:element name="configuration">
<xs:complexType>
<xs:sequence>
<xs:element name="domain"/>
</xs:sequence>
<xs:attribute name="timestamp" type="xs:normalizedString" use="optional"/>
<xs:attribute name="version" type="xs:token" fixed="2.2"/>
</xs:complexType>
</xs:element>
<xs:element name="domain">
<xs:complexType>
<xs:sequence>
<xs:any minOccurs="0"/>
</xs:sequence>
<xs:attribute name="account" type="uid" use="required">
</xs:attribute>
</xs:complexType>
</xs:element>
<xs:simpleType name="uid">
<xs:restriction base="xs:string">
<xs:length value="36"/>
<xs:pattern value="[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
構成.dtd
<!ELEMENT configuration (domain)>
<!ATTLIST configuration
timestamp CDATA #IMPLIED
version CDATA #FIXED "2.2"
xmlns CDATA #IMPLIED
xmlns:xsi CDATA #IMPLIED
xsi:schemaLocation CDATA #IMPLIED>
<!ELEMENT domain ANY>
<!ATTLIST domain account CDATA #IMPLIED>