Add PureXML.Validation.Schematron: compile a Schematron schema (matching schema/pattern/rule/assert/report by local name, so the ISO and legacy namespaces both work) and validate a document. A rule's context XPath selects the nodes it fires on; each assert/report test is evaluated relative to the node via the XPath context-node API. A failed assert is an error, a matched report a warning; within a pattern a node fires the first matching rule. Adds XPath.Query.nodes(over:) returning matched tree nodes so one tree can be queried repeatedly. Closes #52 Closes #53 Closes #25
23 lines
797 B
Swift
23 lines
797 B
Swift
extension PureXML.Validation {
|
|
/// One `<assert>` or `<report>`: a compiled XPath test and its message. An
|
|
/// assert flags when its test is false; a report flags when its test is true.
|
|
struct SchematronAssertion {
|
|
let isReport: Bool
|
|
let test: PureXML.XPath.Query
|
|
let message: String
|
|
}
|
|
|
|
/// One `<rule>`: a compiled context that selects the nodes the rule fires on,
|
|
/// and its assertions.
|
|
struct SchematronRule {
|
|
let context: PureXML.XPath.Query
|
|
let assertions: [SchematronAssertion]
|
|
}
|
|
|
|
/// One `<pattern>`: a list of rules. A node is processed by the first rule in
|
|
/// the pattern whose context selects it (the ISO Schematron firing rule).
|
|
struct SchematronPattern {
|
|
let rules: [SchematronRule]
|
|
}
|
|
}
|