How do I do ISO Schematron validation in .Net

2.1k views Asked by At

I have a NMatrix.schematron.dll to validate xml files with Schematron(1.5).I use the Linqpad to test.But I found that if i use the ISO Schematron Standards,it didn't work. There is my C# code

    void Main()
{
    var xmlResult = "";
    var validator = new Validator();
    var schPath2 = Path.Combine("E:\\validate", "test1.sch");
    try
    {
        validator.AddSchema(schPath2);
        validator.Validate(new XmlTextReader("E:\\validate\\Biz430381170629035686.xml"));
    }
    catch (Exception ex)        
    {
        xmlResult = ex.Message;
    }
    xmlResult.Dump();
}

and this is schematron 1.5 edition:

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.ascc.net/xml/schematron">
  <pattern name="CheckUnique">
      <rule context="*">
          <assert test="1=1">
              OK
          </assert>
      </rule>
  </pattern>  
</schema>

and this is schematron iso edition:

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2"
    xmlns:sqf="http://www.schematron-quickfix.com/validator/process">
    <pattern id="CheckUnique">
        <rule context="*">
            <assert test="1=1">
                OK
            </assert>
        </rule>
    </pattern>  
</schema>

The only different is the namespace.When I changed the 1.5 Edition to ISO Edition,the validate didn't work. Why? Because of the NMatrix.Schematron.dll ? Thanks.Wong.

1

There are 1 answers

0
Nic Gibson On

OK. It looks like your fundamental problem is 14 year old code. In Schema.cs we can see that the namespace for Schematron is hard coded to the pre ISO namespace URI. The code you are using is not designed to work with ISO Schematron.

If you can't take the 'roll it yourself' approach and use the Schematron Skeletons directly then you should perhaps look at https://github.com/gap777/SchemaTron which claims to support ISO Schematron (I've not tried it)