这个 xml 文件
<?xml version="1.0" encoding="utf-8"?>
<root>
<a>Only Text</a>
<a>
<b>Child node</b>
</a>
<a>
<b>Child node</b>
Mixed content
</a>
</root>
和这个 xsd 文件
<?xml version="1.0" encoding="UTF-8"?>
<iso:schema xmlns:iso="http://purl.oclc.org/dsdl/schematron">
<iso:pattern id="children tests">
<iso:rule context="a">
<iso:assert test="empty(child::node())">
Element has nodes
</iso:assert>
<iso:assert test="empty(child::*)">
Element has child elements
</iso:assert>
<iso:assert test="empty(child::text())">
Element has text
</iso:assert>
<iso:report test="child::text() and empty(child::*)">
Element has only text
</iso:report>
</iso:rule>
</iso:pattern>
</iso:schema>
和这段代码
Validator validator = new Validator();
//validator.XmlSchemas.Add("", @"C:\project\Schematron\ConsoleApplication2\shematron\pdfdogschematron.sch");
validator.AddSchema(@"C:\project\Schematron\ConsoleApplication2\shematron\book.xsd");
IXPathNavigable a = validator.Validate(new XmlTextReader(@"C:\project\Schematron\ConsoleApplication2\shematron\dog.xml"));
我正在使用 NMatrix.Schematron 验证器,但它不正确。该方法并不总是异常。