我在哪里可以找到ISO Schematron验证器的Java实现?

Chr*_*ris 5 java schematron

ISO Schematron标准已经出现两年了,但我仍然无法使用ISO Schematron XSLT文件找到Java实现(而不是来自旧版Schematron的文件,例如:http://uploading.com /files/c9c9cb87/SchematronXpath.jar/).

有没有人知道可以从Java方法轻松调用的生产就绪的ISO模式验证器?

Phi*_*ger 9

另外,您可以使用ph-schematron它提供对转换到XSLT的支持以及本机普通Java验证,这几乎在所有情况下都比XSLT版本更快.有关详细信息,请参阅https://github.com/phax/ph-schematron/以及快速介绍.用于检查XML文件是否与Schematron文件匹配的示例代码:

public static boolean validateXMLViaPureSchematron (File aSchematronFile, File aXMLFile) throws Exception { 
  final ISchematronResource aResPure = SchematronResourcePure.fromFile (aSchematronFile);
  if (!aResPure.isValidSchematron ()) 
    throw new IllegalArgumentException ("Invalid Schematron!"); 
  return aResPure.getSchematronValidity(new StreamSource(aXMLFile)).isValid ();
}
Run Code Online (Sandbox Code Playgroud)


Pop*_*ops 6

Probatron4j可以验证ISO Schematron.该网站提供了一个单独的,独立的JAR,旨在从命令行运行,但如果您有源代码,可以很容易地从Java方法调用Probatron .这是我如何做到的简化版本:

public boolean validateSchematron(InputStream xmlDoc, File schematronSchema) {
    // Session = org.probatron.Session; think of it as the Main class
    Session theSession = new Session();
    theSession.setSchemaSysId(schematronSchema.getName());
    theSession.setFsContextDir(schematronSchema.getAbsolutePath());

    // ValidationReport = org.probatron.ValidationReport; the output class
    ValidationReport validationReport = null;
    try
    {
        validationReport = theSession.doValidation(xmlDoc);
    }
    catch(Exception e) { /* ignoring to keep this answer short */ }

    if (validationReport == null ||
        !validationReport.documentPassedValidation()) {
        return false;
    }
    return true;
}
Run Code Online (Sandbox Code Playgroud)

你需要做一些小修改才能让Probatron知道它不是从JAR文件中运行的,但它不需要很长时间.

  • 请注意,Probatron是根据Affero GPL许可的.IANAL,但在商业环境中使用Probatron之前,您可能需要先咨询一下. (2认同)

小智 -1

jing图书馆为我工作。

  • 虽然 jing 确实可以与 Schematron 1.5 配合使用,但它尚不支持 ISO 版本的 Schematron。请参阅[问题 23](http://code.google.com/p/jing-trang/issues/detail?id=23&colspec=ID%20Type%20Status%20Priority%20Stars%20Module%20Summary)。 (3认同)