【问题标题】:Schematron.net structured error reportingSchematron.net 结构化错误报告
【发布时间】:2017-04-19 05:49:11
【问题描述】:

我正在使用 Schematron.net nuget 包,我想知道是否有可能获取对 Validate 的调用的输出,以便以结构化格式提供结果,然后我可以对其进行处理。我现有的解决方案依赖于 try catch 块,并且断言失败都作为错误消息作为异常中的消息返回。有没有办法将这些信息作为 XML 获取?我看过这个post,它提出了一个类似的问题,但答案并不涉及 Schematron.net 实现。

我的代码如下所示:

try
{
   var bookValidator = new Validator();
   bookValidator.AddSchema("book.xsd");
   bookValidator.Validate("book.xml");
}
catch (Exception ex)
{
   Console.WriteLine(ex.Message);
}

【问题讨论】:

    标签: c# xml schematron


    【解决方案1】:

    其实很简单。我刚刚意识到,将合适的 OutputFormatting 枚举传递给 Validator 构造函数可以让我控制异常中消息的格式,如下所示:

    try
    {
       //OutputFormatting is a public enum from the Schematron library. Valid values include boolean, default, Log, simple and XML.
       OutputFormatting format = OutputFormatting.XML;
       var bookValidator = new Validator(format);
       bookValidator.AddSchema("book.xsd");
       bookValidator.Validate("book.xml");
    }
    catch (Exception ex)
    {
       //ex.Message will now be in XML format and can be processed however I want!
       Console.WriteLine(ex.Message);
    }
    

    还有您的结构化结果。我希望这对我有帮助,因为这对我来说并不明显。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-07-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-05
      • 1970-01-01
      • 2013-01-21
      • 2017-09-24
      相关资源
      最近更新 更多