xml - 有没有一种简单的方法可以通过 bash 命令验证 xsd 中的 schematron
问题描述
我有一个项目,我需要将 schematron 添加到我的 xsd。问题是我使用的是不允许验证 schematron 的 xmllint,我找到了其他解决方案,例如使用 xsltproc 和 iso-schematron 但这迫使我将文件夹 iso-schematron 添加到我的项目中。
您是否有更简单的解决方案来使用 bash 命令验证 schematron?
我使用了这种方法,我想使用这个过程进行测试,但它似乎比我的第一个解决方案更复杂。
XSD 代码:
<xs:element name="worker">
<xs:annotation>
<xs:appinfo>
<sch:pattern name="Testing schematron" xmlns:sch="http://purl.oclc.org/dsdl/schematron">
<sch:rule context="worker">
<sch:assert test="id>2"
You have to respect de schema.
</sch:assert>
</sch:pattern>
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="id" type="xs:token"/>
</xs:sequence>
</xs:complexType>
</xs:element>
xml代码:
<worker>
<id>3</id>
</worker>
解决方案 bash :
echo XSD validation
xsltproc iso-schematron-xslt/ExtractSchFromXSD.xsl my_xsd_schema.xsd > schema.sch
xsltproc iso-schematron-xslt/iso_dsdl_include.xsl schema.sch > step1.xsl
xsltproc iso-schematron-xslt/iso_abstract_expand.xsl step1.xsl > step2.xsl
xsltproc iso-schematron-xslt/iso_svrl_for_xslt1.xsl step2.xsl > step3.xsl
xsltproc step3.xsl my_xml_code.xml
rm schema.sch
rm step1.xsl
rm step2.xsl
rm step3.xsl