这个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验证器,但它不正确。该方法始终不会例外。
答案 0 :(得分:0)
我可以建议的第一个问题是你正在使用NMatrix.Schematron,这是一个原生的.NET Schematron 1.5验证器。它不支持ISO schematron。我建议你使用XRouter SchemaTron(可用here)