xsdにスキマトロン検証を追加しようとしています。これは私の新しいxsdです:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
xmlns:sch="http://www.ascc.net/xml/schematron"
elementFormDefault="qualified" >
<xs:element name="books">
<xs:complextype>
<xs:sequence> ;P
<xs:element name="book" type="bookType" maxoccurs="unbounded">
<xs:annotation>
<xs:appinfo>
<sch:pattern id="onLoanTests" xmlns:sch="http://purl.oclc.org/dsdl/schematron">
<sch:rule context="book">
<sch:report test="@on-loan and not(@return-date)">
Every book that is on loan must have a return date
</sch:report>
</sch:rule>
</sch:pattern>
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complextype>
</xs:element>
<xs:complextype name="bookType">
<xs:sequence>
<xs:element name="title" type="xs:string" />
<xs:element name="author" type="xs:string" />
<xs:element name="publication-date" type="xs:string" />
</xs:sequence>
<xs:attribute name="publisher" type="xs:string" use="required" />
<xs:attribute name="on-loan" type="xs:string" use="required" />
<xs:attribute name="return-date" type="xs:string" use="optional" />
</xs:complextype>
</xs:schema>
これは私のテストxmlです:
<books>
<book publisher="ddd" on-loan="sdsd">
<title>idan title</title>
<author>idan author</author>
<publication-date>idan date</publication-date>
</book>
</books>
私が提供したxmlを使用すると、検証エラーは発生しません。
「貸し出し中のすべての本には返却日が必要です」というメッセージが表示され、xmlは無効になると想定しました。理由についての提案?
更新 oXygenxmlエディターでschematron検証を使用して、なんとか機能させることができました。しかし、コードでどのように使用すると思いますか?何か特別なものをインストールする必要がありますか?別のライブラリへのリンク?
Update2 どうやらここの「処理」セクションでは、必要なすべての手順が詳しく説明されています。