如何让 Schematron.net 触发诊断?

How do I get Schematron.net to trigger diagnostic?

我正在使用 Schematron.net nuget 包来验证一些 XML 但我不知道如何正确使用诊断标签。我有以下 XML:

<bk:books xmlns:bk="http://www.example.com/books">
  <bk:book publisher="QUE">
    <bk:title>XML By Example</bk:title>
    <!--<bk:author>Benoit Marchal</bk:author>-->
    <bk:publication-date>1999-12-31</bk:publication-date>
    <bk:retailPrice>9.95</bk:retailPrice>
  </bk:book>
  <bk:book publisher="Addison Wesley">
    <bk:title>Essential C++</bk:title>
    <bk:author>Stanley Lippman</bk:author>
    <bk:publication-date>2000-10-31</bk:publication-date>
    <bk:retailPrice>29.95</bk:retailPrice>
  </bk:book>
</bk:books>

我的简化 Schematron 架构如下所示:

<schema xmlns="http://www.ascc.net/xml/schematron"
        schemaVersion="1.01" >
  <title>A Schema for Books</title>
  <ns prefix="bk" uri="http://www.example.com/books" />
  <pattern id="authorTests">
    <rule context="bk:book">
      <assert test="count(bk:author)!= 0" diagnostics="bookTest">
        A book must have at least one author
      </assert>
    </rule>
  </pattern>
  <diagnostics>
    <diagnostic id="bookTest">
      The book that has no author is <value-of select="bk:title"></value-of>
    </diagnostic>
  </diagnostics>
</schema>

我 运行 练习此模式的代码如下所示:

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

运行时我得到以下控制台输出:

Results from Schematron validation: A Schema for Books
    From pattern ""
        Assert fails: A book must have at least one author
        At: /bk:bk:books[1]/bk:bk:book[1]
            <bk:book publisher="QUE">...</bk:book>
            (Line: 3, Column: 4)
            xmlns:bk="http://www.example.com/books"

为什么我在控制台中看不到诊断标记的输出?

似乎 NMatrix.Schematron 实现不支持完整的 Schematron 功能集。查看源代码后,我根本找不到对诊断元素的任何引用。此外,代码似乎只支持 XPath 1.0 和 Schematron 的早期实现(在命名空间被 ISO 标准化更改之前)。最好的建议是使用 Schematron "Skeleton" 实现作为指南来实现 Schematron 管道,可以在此处找到:http://schematron.com/front-page/the-schematron-skeleton-implementation/