java schematron_java-ph-schematron验证错误消息

我正在使用ph-schematron验证我的XML文件.我能够正确验证文件,但找不到如何生成有关断言失败的报告.

这是我的上下文(兴趣点):

这是我的Schematron模式:

xmlns="http://purl.oclc.org/dsdl/schematron"

xmlns:iso="http://purl.oclc.org/dsdl/schematron"

queryBinding='xslt2'

schemaVersion='ISO19757-3'>

Test ISO schematron file. Introduction mode

This pattern validates call activities with RESERVATION operation code.

err1

err2

这是我的Java代码:

public static boolean validateXMLViaPureSchematron(@Nonnull final String aSchematronFilePath, @Nonnull final File aXMLFile) throws Exception {

final SchematronResourcePure schematronResourcePure = SchematronResourcePure.fromClassPath(aSchematronFilePath);

IPSErrorHandler errorHandler = new CollectingPSErrorHandler();

schematronResourcePure.setErrorHandler(errorHandler);

final boolean validSchematron = schematronResourcePure.isValidSchematron();

if (!validSchematron) {

throw new IllegalArgumentException("Invalid Schematron!");

}

final Source streamSource = new StreamSource(aXMLFile);

final EValidity schematronValidity = schematronResourcePure.getSchematronValidity(streamSource);

return schematronValidity.isValid();

}

我可以通过调用schematronResourcePure.getSchematronValidity(streamSource)看到验证的结果,但是我想查看(一个报告就足够了)哪些规则失败了(err1或err2).我已经阅读了有关SVRL的文章,但我不知道如何生成报告.

谢谢.

解决方法:

只需调用applySchematronValidationToSVRL即可获取完整的SVRL(Schematron验证结果列表)文档.您可以查询失败的断言或报告.

仅打印失败的断言的代码示例:

SchematronOutputType schematronOutputType = schematronResourcePure.applySchematronValidationToSVRL(streamSource);

List failedAsserts = schematronOutputType.getActivePatternAndFiredRuleAndFailedAssert();

for (Object object : failedAsserts) {

if (object instanceof FailedAssert) {

FailedAssert failedAssert = (FailedAssert) object;

System.out.println(failedAssert.getText());

System.out.println(failedAssert.getTest());

}

}

标签:validation,schematron,xml,java

来源: https://codeday.me/bug/20191027/1945303.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值