Xml 使用Schematron和xsltproc验证XSD模式
我很难验证与Schematron结合的SXD模式 按照本文中描述的步骤,我在XSD文档中的Xml 使用Schematron和xsltproc验证XSD模式,xml,validation,xsd,schematron,Xml,Validation,Xsd,Schematron,我很难验证与Schematron结合的SXD模式 按照本文中描述的步骤,我在XSD文档中的标记之间合并了schematron,如下所示: <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="Test"> <xs:annotation>
标记之间合并了schematron,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Test">
<xs:annotation>
<xs:appinfo>
<sch:pattern name="Testing schematron" xmlns:sch="http://purl.oclc.org/dsdl/schematron">
<sch:rule context="Test">
<sch:assert test="@Attribute1">Attribute 1 exists</sch:assert>
</sch:rule>
</sch:pattern>
</xs:appinfo>
</xs:annotation>
<xs:complexType>
<xs:attribute name="Attribute1" type="xs:string" use="optional"/>
<xs:attribute name="Attribute2" type="xs:string" use="optional"/>
</xs:complexType>
</xs:element>
</xs:schema>
属性1存在
本文件旨在测试(或验证)该文件
<?xml version="1.0" encoding="ISO-8859-1"?>
<Test Attribute1="attr1"/>
使用schematron上列出的基于xsltproc的简单脚本。不幸的是,在脚本的最后一步,我收到了以下错误消息
step3.xsl:13: parser error : Extra content at the end of the document
plates select="*|comment()|processing-instruction()" mode="M0"/></axsl:template>
^
cannot parse step3.xsl
step3.xsl:13:解析器错误:文档末尾有额外内容
板材选择=“*|注释()|处理-指令()”模式=“M0”/>
^
无法分析step3.xsl
如果您能帮助我找出此错误的原因,我将不胜感激。您的模式是正确的,并且能够完成预期的功能 这个脚本的问题在于:这个脚本期望接收一个Schematron模式,而您给它一个带有嵌入规则的XML模式,这是另一种beast 要进行验证,您需要运行第一个转换,该转换将从XML模式中提取Schematron并对该结果运行验证 您还可以使用xmllint(libxml)根据XML模式验证文档,这是一种不同的操作 为此,您可以将下载脚本更改为:
#!/bin/bash
echo XSD validation
xmllint -schema $1 $2
echo Step0 ...
xsltproc ExtractSchFromXSD.xsl $1 > schema.sch
echo Step1 ...
xsltproc iso_dsdl_include.xsl schema.sch > step1.xsl
echo Step2 ...
xsltproc iso_abstract_expand.xsl step1.xsl > step2.xsl
echo Step3 ...
xsltproc iso_svrl_for_xslt1.xsl step2.xsl > step3.xsl
echo Validation ...
xsltproc step3.xsl $2 | tee result.svrl
或者,您可以使用本机支持模式中嵌入的Schematron规则的实现,或者使用。谢谢。它起作用了。但是,鉴于XSD2刚刚被标准化,您还会提倡使用Schematron吗?您是指XMLSchema 1.1;)?Schematron仍然比XMLSchema1.1断言灵活得多,XMLSchema1.1断言对您可以使用的XPath表达式施加了限制,Schematron保留了其独特的功能,允许您定义错误消息。我的建议是在XSD1.1满足您的需求时使用它,但请记住,如果您需要更多,您仍然可以使用Schematron。