Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/395.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java PHSchematron验证schematron文件失败,该文件在`pattern`元素中包含`p`元素_Java_Xml_Validation_Xslt_Schematron - Fatal编程技术网

Java PHSchematron验证schematron文件失败,该文件在`pattern`元素中包含`p`元素

Java PHSchematron验证schematron文件失败,该文件在`pattern`元素中包含`p`元素,java,xml,validation,xslt,schematron,Java,Xml,Validation,Xslt,Schematron,目前我正在使用PHSchematron库在Java中验证schematron。如果我将标记作为的子项,那么它会抛出NullPointerException,因为SchematronoutType为null。 我尝试将作为和的子元素,但没有任何问题,尽管XSD表示p元素可能是模式,阶段,模式的子元素。 我不确定问题是否出在PHSchematron的实现上。 我认为xmlns:sch指向1.5 schematron XSD版本 schematron_1.5.xsd: <?xml version

目前我正在使用PHSchematron库在Java中验证schematron。如果我将
标记作为
的子项,那么它会抛出NullPointerException,因为SchematronoutType为null。 我尝试将
作为
的子元素,但没有任何问题,尽管XSD表示
p
元素可能是
模式
阶段
模式
的子元素。 我不确定问题是否出在PHSchematron的实现上。 我认为xmlns:sch指向1.5 schematron XSD版本

schematron_1.5.xsd:

<?xml version="1.0" encoding="UTF-8"?>
<!--  schemaVersion of 2001/02/15  -->
<xs:schema xmlns:sch="http://www.ascc.net/xml/schematron" xmlns="http://www.ascc.net/xml/schematron" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.ascc.net/xml/schematron" version="+//IDN sinica.edu.tw//SGML W3C XML Schema for Schematron 1.5//EN">
    <xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="http://www.w3.org/2001/xml.xsd">
        <xs:annotation>
            <xs:documentation>
                Get access to the xml: attribute groups for xml:lang
            </xs:documentation>
        </xs:annotation>
    </xs:import>
    <xs:annotation>
        <xs:documentation source="http://www.ascc.net/xml/resource/schematron/schematron.html" xml:lang="en"/>
    </xs:annotation>
    <xs:element name="active">
        <xs:complexType mixed="true">
            <xs:choice minOccurs="0" maxOccurs="unbounded">
                <xs:element ref="sch:dir"/>
                <xs:element ref="sch:emph"/>
                <xs:element ref="sch:span"/>
            </xs:choice>
            <xs:attribute name="pattern" type="xs:IDREF" use="required"/>
        </xs:complexType>
    </xs:element>
    <xs:element name="assert">
        <xs:complexType mixed="true">
            <xs:choice minOccurs="0" maxOccurs="unbounded">
                <xs:element ref="sch:name"/>
                <xs:element ref="sch:emph"/>
                <xs:element ref="sch:dir"/>
                <xs:element ref="sch:span"/>
                <xs:any namespace="##other" processContents="lax"/>
            </xs:choice>
            <xs:attribute name="test" type="xs:string" use="required"/>
            <xs:attribute name="role" type="xs:NMTOKEN"/>
            <xs:attribute name="id" type="xs:string"/>
            <xs:attribute name="diagnostics" type="xs:IDREFS"/>
            <xs:attribute name="icon" type="xs:anyURI"/>
            <xs:attribute name="subject" type="xs:string" default="."/>
            <xs:attribute ref="xml:lang"/>
            <xs:anyAttribute namespace="##other" processContents="lax"/>
        </xs:complexType>
    </xs:element>
    <xs:element name="diagnostic">
        <xs:complexType mixed="true">
            <xs:choice minOccurs="0" maxOccurs="unbounded">
                <xs:element ref="sch:value-of"/>
                <xs:element ref="sch:emph"/>
                <xs:element ref="sch:dir"/>
                <xs:element ref="sch:span"/>
                <xs:any namespace="##other" processContents="lax"/>
            </xs:choice>
            <xs:attribute name="id" type="xs:ID" use="required"/>
            <xs:attribute name="icon" type="xs:anyURI"/>
            <xs:attribute ref="xml:lang"/>
            <xs:anyAttribute namespace="##other" processContents="lax"/>
        </xs:complexType>
    </xs:element>
    <xs:element name="diagnostics">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="diagnostic" minOccurs="0" maxOccurs="unbounded"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="dir">
        <xs:complexType>
            <xs:simpleContent>
                <xs:extension base="xs:string">
                    <xs:attribute name="value">
                        <xs:simpleType>
                            <xs:restriction base="xs:NMTOKEN">
                                <xs:enumeration value="ltr"/>
                                <xs:enumeration value="rtl"/>
                            </xs:restriction>
                        </xs:simpleType>
                    </xs:attribute>
                </xs:extension>
            </xs:simpleContent>
        </xs:complexType>
    </xs:element>
    <xs:element name="emph" type="xs:string"/>
    <xs:element name="extends">
        <xs:complexType>
            <xs:attribute name="rule" type="xs:string" use="required"/>
        </xs:complexType>
    </xs:element>
    <xs:element name="key">
        <xs:complexType>
            <xs:attribute name="name" type="xs:NMTOKEN" use="required"/>
            <xs:attribute name="path" type="xs:string" use="required"/>
            <xs:attribute name="icon" type="xs:anyURI"/>
        </xs:complexType>
    </xs:element>
    <xs:element name="name">
        <xs:complexType>
            <xs:attribute name="path" type="xs:string" default="."/>
        </xs:complexType>
    </xs:element>
    <xs:element name="ns">
        <xs:complexType>
            <xs:attribute name="uri" type="xs:anyURI" use="required"/>
            <xs:attribute name="prefix" type="xs:NCName"/>
        </xs:complexType>
    </xs:element>
    <xs:element name="p">
        <xs:complexType mixed="true">
            <xs:choice minOccurs="0" maxOccurs="unbounded">
                <xs:element ref="sch:dir"/>
                <xs:element ref="sch:emph"/>
                <xs:element ref="sch:span"/>
            </xs:choice>
            <xs:attribute name="id" type="xs:string"/>
            <xs:attribute name="class" type="xs:string"/>
            <xs:attribute name="icon" type="xs:anyURI"/>
            <xs:attribute ref="xml:lang"/>
            <xs:anyAttribute namespace="##other" processContents="lax"/>
        </xs:complexType>
    </xs:element>
    <xs:element name="pattern">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="p" minOccurs="0" maxOccurs="unbounded"/>
                <xs:element ref="sch:rule" maxOccurs="unbounded"/>
            </xs:sequence>
            <xs:attribute name="name" type="xs:string" use="required"/>
            <xs:attribute name="see" type="xs:anyURI"/>
            <xs:attribute name="id" type="xs:string"/>
            <xs:attribute name="icon" type="xs:anyURI"/>
        </xs:complexType>
    </xs:element>
    <xs:element name="phase">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="sch:p" minOccurs="0" maxOccurs="unbounded"/>
                <xs:element ref="sch:active" maxOccurs="unbounded"/>
            </xs:sequence>
            <xs:attribute name="id" type="xs:string" use="required"/>
            <xs:attribute name="fpi" type="xs:string"/>
            <xs:attribute name="icon" type="xs:anyURI"/>
        </xs:complexType>
    </xs:element>
    <xs:element name="report">
        <xs:complexType mixed="true">
            <xs:choice minOccurs="0" maxOccurs="unbounded">
                <xs:element ref="sch:name"/>
                <xs:element ref="sch:emph"/>
                <xs:element ref="sch:dir"/>
                <xs:element ref="sch:span"/>
                <xs:any namespace="##other" processContents="lax"/>
            </xs:choice>
            <xs:attribute name="test" type="xs:string" use="required"/>
            <xs:attribute name="role" type="xs:NMTOKEN"/>
            <xs:attribute name="id" type="xs:string"/>
            <xs:attribute name="diagnostics" type="xs:IDREFS"/>
            <xs:attribute name="icon" type="xs:anyURI"/>
            <xs:attribute name="subject" type="xs:string" default="."/>
            <xs:attribute ref="xml:lang"/>
        </xs:complexType>
    </xs:element>
    <xs:element name="rule">
        <xs:complexType>
            <xs:choice maxOccurs="unbounded">
                <xs:element ref="sch:assert"/>
                <xs:element ref="sch:report"/>
                <xs:element ref="sch:key"/>
                <xs:element ref="sch:extends"/>
            </xs:choice>
            <xs:attribute name="context" type="xs:string"/>
            <xs:attribute name="abstract" type="xs:boolean" default="false"/>
            <xs:attribute name="role" type="xs:NMTOKEN"/>
            <xs:attribute name="id" type="xs:string"/>
        </xs:complexType>
    </xs:element>
    <xs:element name="schema">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="sch:title" minOccurs="0"/>
                <xs:element ref="sch:ns" minOccurs="0" maxOccurs="unbounded"/>
                <xs:element ref="sch:p" minOccurs="0" maxOccurs="unbounded"/>
                <xs:element ref="sch:phase" minOccurs="0" maxOccurs="unbounded"/>
                <xs:element ref="sch:pattern" maxOccurs="unbounded"/>
                <xs:element ref="sch:p" minOccurs="0" maxOccurs="unbounded"/>
                <xs:element ref="sch:diagnostics" minOccurs="0"/>
            </xs:sequence>
            <xs:attribute name="id" type="xs:ID"/>
            <xs:attribute name="fpi" type="xs:string"/>
            <xs:attribute name="schemaVersion" type="xs:string"/>
            <xs:attribute name="defaultPhase" type="xs:string"/>
            <xs:attribute name="icon" type="xs:anyURI"/>
            <xs:attribute name="ns" type="xs:anyURI"/>
            <xs:attribute name="version" type="xs:string" default="1.5"/>
            <xs:attribute ref="xml:lang"/>
            <xs:anyAttribute namespace="##other" processContents="lax"/>
        </xs:complexType>
        <xs:unique name="assertId">
            <xs:selector xpath="sch:pattern/sch:rule/sch:assert"/>
            <xs:field xpath="@id"/>
        </xs:unique>
        <xs:unique name="reportId">
            <xs:selector xpath="sch:pattern/sch:rule/sch:report"/>
            <xs:field xpath="@id"/>
        </xs:unique>
        <xs:unique name="ruleId">
            <xs:selector xpath="sch:pattern/sch:rule"/>
            <xs:field xpath="@id"/>
        </xs:unique>
        <xs:unique name="patternId">
            <xs:selector xpath="sch:pattern"/>
            <xs:field xpath="@id"/>
        </xs:unique>
        <xs:unique name="pId">
            <xs:selector xpath=".//sch:p"/>
            <xs:field xpath="@id"/>
        </xs:unique>
        <xs:key name="phaseId">
            <xs:selector xpath="sch:phase"/>
            <xs:field xpath="@id"/>
        </xs:key>
        <xs:keyref name="activePattern" refer="patternId">
            <xs:selector xpath="sch:phase/sch:active"/>
            <xs:field xpath="@pattern"/>
        </xs:keyref>
        <xs:keyref name="extendsRule" refer="ruleId">
            <xs:selector xpath="sch:pattern/sch:rule/sch:extends"/>
            <xs:field xpath="@rule"/>
        </xs:keyref>
        <xs:keyref name="defaultPhase" refer="phaseId">
            <xs:selector xpath="."/>
            <xs:field xpath="@defaultPhase"/>
        </xs:keyref>
        <!--  Define the identity constraints  -->
    </xs:element>
    <xs:element name="span">
        <xs:complexType>
            <xs:simpleContent>
                <xs:extension base="xs:string">
                    <xs:attribute name="class" type="xs:string"/>
                </xs:extension>
            </xs:simpleContent>
        </xs:complexType>
    </xs:element>
    <xs:element name="title">
        <xs:complexType mixed="true">
            <xs:choice minOccurs="0" maxOccurs="unbounded">
                <xs:element ref="sch:dir"/>
            </xs:choice>
        </xs:complexType>
    </xs:element>
    <xs:element name="value-of">
        <xs:complexType>
            <xs:attribute name="select" type="xs:string" use="required"/>
        </xs:complexType>
    </xs:element>
</xs:schema>
主要方法:

 SchematronOutputType outputType = SchematronUtil.validateXMLViaXSLTSchematronFull(schematronFile, xmlFile);

            if (outputType == null){
                throw new Exception("SchematronOutputType null");
            }

            List<SVRLSuccessfulReport> succeededList = SVRLHelper.getAllSuccessfulReports(outputType);
            for (SVRLSuccessfulReport succeededReport : succeededList){
                System.out.println(succeededReport.getTest());
            }

            int i = 1;
            List<SVRLFailedAssert> failedList = SVRLHelper.getAllFailedAssertions(outputType);
            for (SVRLFailedAssert failedAssert : failedList) {
                System.out.println(i++ + ". Location:" + failedAssert.getLocation());
                System.out.println("Test: " + failedAssert.getTest());
                System.out.println("Text: " + failedAssert.getText());

                List<DiagnosticReference> diagnisticReferences = failedAssert.getDiagnisticReferences();
                for (DiagnosticReference diagnisticRef : diagnisticReferences) {
                    System.out.println("Diag ref: " + diagnisticRef.getDiagnostic());
                    System.out.println("Diag text: " + diagnisticRef.getText());
                }
            }

            if (failedList.isEmpty()){
                System.out.println("PASS");
            }
            else{
                System.out.println("FAIL");
            }
schematronouttype outputType=SchematronUtil.validateXMLViaXSLTSchematronFull(schematronFile,xmlFile);
if(outputType==null){
抛出新异常(“SchematronOutputType null”);
}
List SucceeedList=SVRLHelper.getAllSuccessfulReports(outputType);
对于(SVRL成功报告成功报告:成功列表){
System.out.println(succeedeReport.getTest());
}
int i=1;
List failedList=SVRLHelper.getAllFailedAssertions(outputType);
对于(SVRLFailedAssert failedAssert:failedList){
System.out.println(i++.Location:“+failedAssert.getLocation());
System.out.println(“测试:+failedAssert.getTest());
System.out.println(“Text:+failedAssert.getText());
List DiagnosticReferences=failedAssert.GetDiagnosticReferences();
for(DiagnosticReference DiagnosticRef:DiagnosticReferences){
System.out.println(“Diag ref:+diagnostiref.getDiagnostic());
System.out.println(“诊断文本:+diagnisticRef.getText());
}
}
if(failedList.isEmpty()){
系统输出打印项次(“通过”);
}
否则{
系统输出打印项次(“失败”);
}

根据一般ISO Schematron规则进行测试,Schematron文档是正确的,除了
targetNamespace
属性。在其中使用默认名称空间
xmlns=“…”
也没有多大意义,因为所有元素都有前缀

Schematron

<?xml version="1.0" encoding="UTF-8"?>
<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">   
   <sch:pattern id="sampleValidation">   
        <sch:title>PatternTitle</sch:title>
        <sch:p>A paragraph</sch:p>
        <sch:rule context="CCC">
            <assert test="normalize-space(.) and *">Source contains an empty element</assert>
        </sch:rule>  
   </sch:pattern>
</sch:schema>
所有这些都可以通过修改XML模式来解决,以下是一个有效的版本:

XML模式

<?xml version="1.0" encoding="UTF-8"?>
<!--  schemaVersion of 2001/02/15  -->
<xs:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" xmlns="http://purl.oclc.org/dsdl/schematron" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://purl.oclc.org/dsdl/schematron" version="+//IDN sinica.edu.tw//SGML W3C XML Schema for Schematron 1.5//EN">
    <xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="http://www.w3.org/2001/xml.xsd">
        <xs:annotation>
            <xs:documentation>
                Get access to the xml: attribute groups for xml:lang
            </xs:documentation>
        </xs:annotation>
    </xs:import>
    <xs:annotation>
        <xs:documentation source="http://www.ascc.net/xml/resource/schematron/schematron.html" xml:lang="en"/>
    </xs:annotation>
    <xs:element name="active">
        <xs:complexType mixed="true">
            <xs:choice minOccurs="0" maxOccurs="unbounded">
                <xs:element ref="sch:dir"/>
                <xs:element ref="sch:emph"/>
                <xs:element ref="sch:span"/>
            </xs:choice>
            <xs:attribute name="pattern" type="xs:IDREF" use="required"/>
        </xs:complexType>
    </xs:element>
    <xs:element name="assert">
        <xs:complexType mixed="true">
            <xs:choice minOccurs="0" maxOccurs="unbounded">
                <xs:element ref="sch:name"/>
                <xs:element ref="sch:emph"/>
                <xs:element ref="sch:dir"/>
                <xs:element ref="sch:span"/>
                <xs:any namespace="##other" processContents="lax"/>
            </xs:choice>
            <xs:attribute name="test" type="xs:string" use="required"/>
            <xs:attribute name="role" type="xs:NMTOKEN"/>
            <xs:attribute name="id" type="xs:string"/>
            <xs:attribute name="diagnostics" type="xs:IDREFS"/>
            <xs:attribute name="icon" type="xs:anyURI"/>
            <xs:attribute name="subject" type="xs:string" default="."/>
            <xs:attribute ref="xml:lang"/>
            <xs:anyAttribute namespace="##other" processContents="lax"/>
        </xs:complexType>
    </xs:element>
    <xs:element name="diagnostic">
        <xs:complexType mixed="true">
            <xs:choice minOccurs="0" maxOccurs="unbounded">
                <xs:element ref="sch:value-of"/>
                <xs:element ref="sch:emph"/>
                <xs:element ref="sch:dir"/>
                <xs:element ref="sch:span"/>
                <xs:any namespace="##other" processContents="lax"/>
            </xs:choice>
            <xs:attribute name="id" type="xs:ID" use="required"/>
            <xs:attribute name="icon" type="xs:anyURI"/>
            <xs:attribute ref="xml:lang"/>
            <xs:anyAttribute namespace="##other" processContents="lax"/>
        </xs:complexType>
    </xs:element>
    <xs:element name="diagnostics">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="diagnostic" minOccurs="0" maxOccurs="unbounded"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="dir">
        <xs:complexType>
            <xs:simpleContent>
                <xs:extension base="xs:string">
                    <xs:attribute name="value">
                        <xs:simpleType>
                            <xs:restriction base="xs:NMTOKEN">
                                <xs:enumeration value="ltr"/>
                                <xs:enumeration value="rtl"/>
                            </xs:restriction>
                        </xs:simpleType>
                    </xs:attribute>
                </xs:extension>
            </xs:simpleContent>
        </xs:complexType>
    </xs:element>
    <xs:element name="emph" type="xs:string"/>
    <xs:element name="extends">
        <xs:complexType>
            <xs:attribute name="rule" type="xs:string" use="required"/>
        </xs:complexType>
    </xs:element>
    <xs:element name="key">
        <xs:complexType>
            <xs:attribute name="name" type="xs:NMTOKEN" use="required"/>
            <xs:attribute name="path" type="xs:string" use="required"/>
            <xs:attribute name="icon" type="xs:anyURI"/>
        </xs:complexType>
    </xs:element>
    <xs:element name="name">
        <xs:complexType>
            <xs:attribute name="path" type="xs:string" default="." />
        </xs:complexType>
    </xs:element>
    <xs:element name="ns">
        <xs:complexType>
            <xs:attribute name="uri" type="xs:anyURI" use="required"/>
            <xs:attribute name="prefix" type="xs:NCName"/>
        </xs:complexType>
    </xs:element>
    <xs:element name="p">
        <xs:complexType mixed="true">
            <xs:choice minOccurs="0" maxOccurs="unbounded">
                <xs:element ref="sch:dir"/>
                <xs:element ref="sch:emph"/>
                <xs:element ref="sch:span"/>
            </xs:choice>
            <xs:attribute name="id" type="xs:string"/>
            <xs:attribute name="class" type="xs:string"/>
            <xs:attribute name="icon" type="xs:anyURI"/>
            <xs:attribute ref="xml:lang"/>
            <xs:anyAttribute namespace="##other" processContents="lax"/>
        </xs:complexType>
    </xs:element>
    <xs:element name="pattern">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="sch:title" minOccurs="0"/>
                <xs:element ref="sch:p" minOccurs="0" maxOccurs="unbounded"/>
                <xs:element ref="sch:rule" maxOccurs="unbounded"/>
            </xs:sequence>
            <xs:attribute name="name" type="xs:string" use="optional"/>
            <xs:attribute name="see" type="xs:anyURI"/>
            <xs:attribute name="id" type="xs:string"/>
            <xs:attribute name="icon" type="xs:anyURI"/>
        </xs:complexType>
    </xs:element>
    <xs:element name="phase">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="sch:p" minOccurs="0" maxOccurs="unbounded"/>
                <xs:element ref="sch:active" maxOccurs="unbounded"/>
            </xs:sequence>
            <xs:attribute name="id" type="xs:string" use="required"/>
            <xs:attribute name="fpi" type="xs:string"/>
            <xs:attribute name="icon" type="xs:anyURI"/>
        </xs:complexType>
    </xs:element>
    <xs:element name="report">
        <xs:complexType mixed="true">
            <xs:choice minOccurs="0" maxOccurs="unbounded">
                <xs:element ref="sch:name"/>
                <xs:element ref="sch:emph"/>
                <xs:element ref="sch:dir"/>
                <xs:element ref="sch:span"/>
                <xs:any namespace="##other" processContents="lax"/>
            </xs:choice>
            <xs:attribute name="test" type="xs:string" use="required"/>
            <xs:attribute name="role" type="xs:NMTOKEN"/>
            <xs:attribute name="id" type="xs:string"/>
            <xs:attribute name="diagnostics" type="xs:IDREFS"/>
            <xs:attribute name="icon" type="xs:anyURI"/>
            <xs:attribute name="subject" type="xs:string" default="."/>
            <xs:attribute ref="xml:lang"/>
        </xs:complexType>
    </xs:element>
    <xs:element name="rule">
        <xs:complexType>
            <xs:choice maxOccurs="unbounded">
                <xs:element ref="sch:assert"/>
                <xs:element ref="sch:report"/>
                <xs:element ref="sch:key"/>
                <xs:element ref="sch:extends"/>
            </xs:choice>
            <xs:attribute name="context" type="xs:string"/>
            <xs:attribute name="abstract" type="xs:boolean" default="false"/>
            <xs:attribute name="role" type="xs:NMTOKEN"/>
            <xs:attribute name="id" type="xs:string"/>
        </xs:complexType>
    </xs:element>
    <xs:element name="schema">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="sch:title" minOccurs="0"/>
                <xs:element ref="sch:ns" minOccurs="0" maxOccurs="unbounded"/>
                <xs:element ref="sch:p" minOccurs="0" maxOccurs="unbounded"/>
                <xs:element ref="sch:phase" minOccurs="0" maxOccurs="unbounded"/>
                <xs:element ref="sch:pattern" maxOccurs="unbounded"/>
                <xs:element ref="sch:p" minOccurs="0" maxOccurs="unbounded"/>
                <xs:element ref="sch:diagnostics" minOccurs="0"/>
            </xs:sequence>
            <xs:attribute name="id" type="xs:ID"/>
            <xs:attribute name="fpi" type="xs:string"/>
            <xs:attribute name="schemaVersion" type="xs:string"/>
            <xs:attribute name="defaultPhase" type="xs:string"/>
            <xs:attribute name="icon" type="xs:anyURI"/>
            <xs:attribute name="ns" type="xs:anyURI"/>
            <xs:attribute name="version" type="xs:string" default="1.5"/>
            <xs:attribute ref="xml:lang"/>
            <xs:attribute name="queryBinding" type="xs:string"/>
            <xs:anyAttribute namespace="##other" processContents="lax"/>
        </xs:complexType>
        <xs:unique name="assertId">
            <xs:selector xpath="sch:pattern/sch:rule/sch:assert"/>
            <xs:field xpath="@id"/>
        </xs:unique>
        <xs:unique name="reportId">
            <xs:selector xpath="sch:pattern/sch:rule/sch:report"/>
            <xs:field xpath="@id"/>
        </xs:unique>
        <xs:unique name="ruleId">
            <xs:selector xpath="sch:pattern/sch:rule"/>
            <xs:field xpath="@id"/>
        </xs:unique>
        <xs:unique name="patternId">
            <xs:selector xpath="sch:pattern"/>
            <xs:field xpath="@id"/>
        </xs:unique>
        <xs:unique name="pId">
            <xs:selector xpath=".//sch:p"/>
            <xs:field xpath="@id"/>
        </xs:unique>
        <xs:key name="phaseId">
            <xs:selector xpath="sch:phase"/>
            <xs:field xpath="@id"/>
        </xs:key>
        <xs:keyref name="activePattern" refer="patternId">
            <xs:selector xpath="sch:phase/sch:active"/>
            <xs:field xpath="@pattern"/>
        </xs:keyref>
        <xs:keyref name="extendsRule" refer="ruleId">
            <xs:selector xpath="sch:pattern/sch:rule/sch:extends"/>
            <xs:field xpath="@rule"/>
        </xs:keyref>
        <xs:keyref name="defaultPhase" refer="phaseId">
            <xs:selector xpath="."/>
            <xs:field xpath="@defaultPhase"/>
        </xs:keyref>
        <!--  Define the identity constraints  -->
    </xs:element>
    <xs:element name="span">
        <xs:complexType>
            <xs:simpleContent>
                <xs:extension base="xs:string">
                    <xs:attribute name="class" type="xs:string"/>
                </xs:extension>
            </xs:simpleContent>
        </xs:complexType>
    </xs:element>
    <xs:element name="title">
        <xs:complexType mixed="true">
            <xs:choice minOccurs="0" maxOccurs="unbounded">
                <xs:element ref="sch:dir"/>
            </xs:choice>
        </xs:complexType>
    </xs:element>
    <xs:element name="value-of">
        <xs:complexType>
            <xs:attribute name="select" type="xs:string" use="required"/>
        </xs:complexType>
    </xs:element>
</xs:schema>

获取对xml:lang的xml:attribute组的访问权
但是请记住:这个XSD文档已经过时,并且没有反映Schematron规范的最新更改。很可能会有其他问题

作为替代,您可以使用最近的。确保下载所有架构组件,然后根据进行验证。

针对gener进行测试
<?xml version="1.0" encoding="UTF-8"?>
<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">   
   <sch:pattern id="sampleValidation">   
        <sch:title>PatternTitle</sch:title>
        <sch:p>A paragraph</sch:p>
        <sch:rule context="CCC">
            <assert test="normalize-space(.) and *">Source contains an empty element</assert>
        </sch:rule>  
   </sch:pattern>
</sch:schema>
Attribute 'queryBinding' is not allowed to appear in element 'sch:schema'.
Attribute 'name' must appear on element 'sch:pattern'.
Invalid content was found starting with element '{"http://purl.oclc.org/dsdl/schematron":title}'. One of '{"http://purl.oclc.org/dsdl/schematron":p, "http://purl.oclc.org/dsdl/schematron":rule}' is expected.
<?xml version="1.0" encoding="UTF-8"?>
<!--  schemaVersion of 2001/02/15  -->
<xs:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" xmlns="http://purl.oclc.org/dsdl/schematron" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://purl.oclc.org/dsdl/schematron" version="+//IDN sinica.edu.tw//SGML W3C XML Schema for Schematron 1.5//EN">
    <xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="http://www.w3.org/2001/xml.xsd">
        <xs:annotation>
            <xs:documentation>
                Get access to the xml: attribute groups for xml:lang
            </xs:documentation>
        </xs:annotation>
    </xs:import>
    <xs:annotation>
        <xs:documentation source="http://www.ascc.net/xml/resource/schematron/schematron.html" xml:lang="en"/>
    </xs:annotation>
    <xs:element name="active">
        <xs:complexType mixed="true">
            <xs:choice minOccurs="0" maxOccurs="unbounded">
                <xs:element ref="sch:dir"/>
                <xs:element ref="sch:emph"/>
                <xs:element ref="sch:span"/>
            </xs:choice>
            <xs:attribute name="pattern" type="xs:IDREF" use="required"/>
        </xs:complexType>
    </xs:element>
    <xs:element name="assert">
        <xs:complexType mixed="true">
            <xs:choice minOccurs="0" maxOccurs="unbounded">
                <xs:element ref="sch:name"/>
                <xs:element ref="sch:emph"/>
                <xs:element ref="sch:dir"/>
                <xs:element ref="sch:span"/>
                <xs:any namespace="##other" processContents="lax"/>
            </xs:choice>
            <xs:attribute name="test" type="xs:string" use="required"/>
            <xs:attribute name="role" type="xs:NMTOKEN"/>
            <xs:attribute name="id" type="xs:string"/>
            <xs:attribute name="diagnostics" type="xs:IDREFS"/>
            <xs:attribute name="icon" type="xs:anyURI"/>
            <xs:attribute name="subject" type="xs:string" default="."/>
            <xs:attribute ref="xml:lang"/>
            <xs:anyAttribute namespace="##other" processContents="lax"/>
        </xs:complexType>
    </xs:element>
    <xs:element name="diagnostic">
        <xs:complexType mixed="true">
            <xs:choice minOccurs="0" maxOccurs="unbounded">
                <xs:element ref="sch:value-of"/>
                <xs:element ref="sch:emph"/>
                <xs:element ref="sch:dir"/>
                <xs:element ref="sch:span"/>
                <xs:any namespace="##other" processContents="lax"/>
            </xs:choice>
            <xs:attribute name="id" type="xs:ID" use="required"/>
            <xs:attribute name="icon" type="xs:anyURI"/>
            <xs:attribute ref="xml:lang"/>
            <xs:anyAttribute namespace="##other" processContents="lax"/>
        </xs:complexType>
    </xs:element>
    <xs:element name="diagnostics">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="diagnostic" minOccurs="0" maxOccurs="unbounded"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="dir">
        <xs:complexType>
            <xs:simpleContent>
                <xs:extension base="xs:string">
                    <xs:attribute name="value">
                        <xs:simpleType>
                            <xs:restriction base="xs:NMTOKEN">
                                <xs:enumeration value="ltr"/>
                                <xs:enumeration value="rtl"/>
                            </xs:restriction>
                        </xs:simpleType>
                    </xs:attribute>
                </xs:extension>
            </xs:simpleContent>
        </xs:complexType>
    </xs:element>
    <xs:element name="emph" type="xs:string"/>
    <xs:element name="extends">
        <xs:complexType>
            <xs:attribute name="rule" type="xs:string" use="required"/>
        </xs:complexType>
    </xs:element>
    <xs:element name="key">
        <xs:complexType>
            <xs:attribute name="name" type="xs:NMTOKEN" use="required"/>
            <xs:attribute name="path" type="xs:string" use="required"/>
            <xs:attribute name="icon" type="xs:anyURI"/>
        </xs:complexType>
    </xs:element>
    <xs:element name="name">
        <xs:complexType>
            <xs:attribute name="path" type="xs:string" default="." />
        </xs:complexType>
    </xs:element>
    <xs:element name="ns">
        <xs:complexType>
            <xs:attribute name="uri" type="xs:anyURI" use="required"/>
            <xs:attribute name="prefix" type="xs:NCName"/>
        </xs:complexType>
    </xs:element>
    <xs:element name="p">
        <xs:complexType mixed="true">
            <xs:choice minOccurs="0" maxOccurs="unbounded">
                <xs:element ref="sch:dir"/>
                <xs:element ref="sch:emph"/>
                <xs:element ref="sch:span"/>
            </xs:choice>
            <xs:attribute name="id" type="xs:string"/>
            <xs:attribute name="class" type="xs:string"/>
            <xs:attribute name="icon" type="xs:anyURI"/>
            <xs:attribute ref="xml:lang"/>
            <xs:anyAttribute namespace="##other" processContents="lax"/>
        </xs:complexType>
    </xs:element>
    <xs:element name="pattern">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="sch:title" minOccurs="0"/>
                <xs:element ref="sch:p" minOccurs="0" maxOccurs="unbounded"/>
                <xs:element ref="sch:rule" maxOccurs="unbounded"/>
            </xs:sequence>
            <xs:attribute name="name" type="xs:string" use="optional"/>
            <xs:attribute name="see" type="xs:anyURI"/>
            <xs:attribute name="id" type="xs:string"/>
            <xs:attribute name="icon" type="xs:anyURI"/>
        </xs:complexType>
    </xs:element>
    <xs:element name="phase">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="sch:p" minOccurs="0" maxOccurs="unbounded"/>
                <xs:element ref="sch:active" maxOccurs="unbounded"/>
            </xs:sequence>
            <xs:attribute name="id" type="xs:string" use="required"/>
            <xs:attribute name="fpi" type="xs:string"/>
            <xs:attribute name="icon" type="xs:anyURI"/>
        </xs:complexType>
    </xs:element>
    <xs:element name="report">
        <xs:complexType mixed="true">
            <xs:choice minOccurs="0" maxOccurs="unbounded">
                <xs:element ref="sch:name"/>
                <xs:element ref="sch:emph"/>
                <xs:element ref="sch:dir"/>
                <xs:element ref="sch:span"/>
                <xs:any namespace="##other" processContents="lax"/>
            </xs:choice>
            <xs:attribute name="test" type="xs:string" use="required"/>
            <xs:attribute name="role" type="xs:NMTOKEN"/>
            <xs:attribute name="id" type="xs:string"/>
            <xs:attribute name="diagnostics" type="xs:IDREFS"/>
            <xs:attribute name="icon" type="xs:anyURI"/>
            <xs:attribute name="subject" type="xs:string" default="."/>
            <xs:attribute ref="xml:lang"/>
        </xs:complexType>
    </xs:element>
    <xs:element name="rule">
        <xs:complexType>
            <xs:choice maxOccurs="unbounded">
                <xs:element ref="sch:assert"/>
                <xs:element ref="sch:report"/>
                <xs:element ref="sch:key"/>
                <xs:element ref="sch:extends"/>
            </xs:choice>
            <xs:attribute name="context" type="xs:string"/>
            <xs:attribute name="abstract" type="xs:boolean" default="false"/>
            <xs:attribute name="role" type="xs:NMTOKEN"/>
            <xs:attribute name="id" type="xs:string"/>
        </xs:complexType>
    </xs:element>
    <xs:element name="schema">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="sch:title" minOccurs="0"/>
                <xs:element ref="sch:ns" minOccurs="0" maxOccurs="unbounded"/>
                <xs:element ref="sch:p" minOccurs="0" maxOccurs="unbounded"/>
                <xs:element ref="sch:phase" minOccurs="0" maxOccurs="unbounded"/>
                <xs:element ref="sch:pattern" maxOccurs="unbounded"/>
                <xs:element ref="sch:p" minOccurs="0" maxOccurs="unbounded"/>
                <xs:element ref="sch:diagnostics" minOccurs="0"/>
            </xs:sequence>
            <xs:attribute name="id" type="xs:ID"/>
            <xs:attribute name="fpi" type="xs:string"/>
            <xs:attribute name="schemaVersion" type="xs:string"/>
            <xs:attribute name="defaultPhase" type="xs:string"/>
            <xs:attribute name="icon" type="xs:anyURI"/>
            <xs:attribute name="ns" type="xs:anyURI"/>
            <xs:attribute name="version" type="xs:string" default="1.5"/>
            <xs:attribute ref="xml:lang"/>
            <xs:attribute name="queryBinding" type="xs:string"/>
            <xs:anyAttribute namespace="##other" processContents="lax"/>
        </xs:complexType>
        <xs:unique name="assertId">
            <xs:selector xpath="sch:pattern/sch:rule/sch:assert"/>
            <xs:field xpath="@id"/>
        </xs:unique>
        <xs:unique name="reportId">
            <xs:selector xpath="sch:pattern/sch:rule/sch:report"/>
            <xs:field xpath="@id"/>
        </xs:unique>
        <xs:unique name="ruleId">
            <xs:selector xpath="sch:pattern/sch:rule"/>
            <xs:field xpath="@id"/>
        </xs:unique>
        <xs:unique name="patternId">
            <xs:selector xpath="sch:pattern"/>
            <xs:field xpath="@id"/>
        </xs:unique>
        <xs:unique name="pId">
            <xs:selector xpath=".//sch:p"/>
            <xs:field xpath="@id"/>
        </xs:unique>
        <xs:key name="phaseId">
            <xs:selector xpath="sch:phase"/>
            <xs:field xpath="@id"/>
        </xs:key>
        <xs:keyref name="activePattern" refer="patternId">
            <xs:selector xpath="sch:phase/sch:active"/>
            <xs:field xpath="@pattern"/>
        </xs:keyref>
        <xs:keyref name="extendsRule" refer="ruleId">
            <xs:selector xpath="sch:pattern/sch:rule/sch:extends"/>
            <xs:field xpath="@rule"/>
        </xs:keyref>
        <xs:keyref name="defaultPhase" refer="phaseId">
            <xs:selector xpath="."/>
            <xs:field xpath="@defaultPhase"/>
        </xs:keyref>
        <!--  Define the identity constraints  -->
    </xs:element>
    <xs:element name="span">
        <xs:complexType>
            <xs:simpleContent>
                <xs:extension base="xs:string">
                    <xs:attribute name="class" type="xs:string"/>
                </xs:extension>
            </xs:simpleContent>
        </xs:complexType>
    </xs:element>
    <xs:element name="title">
        <xs:complexType mixed="true">
            <xs:choice minOccurs="0" maxOccurs="unbounded">
                <xs:element ref="sch:dir"/>
            </xs:choice>
        </xs:complexType>
    </xs:element>
    <xs:element name="value-of">
        <xs:complexType>
            <xs:attribute name="select" type="xs:string" use="required"/>
        </xs:complexType>
    </xs:element>
</xs:schema>