pub struct Report {
pub title: Option<String>,
pub phase: Option<String>,
pub schema_version: Option<String>,
pub namespaces: Vec<Ns>,
pub patterns: Vec<ActivePattern>,
}Expand description
The result of validating one document against one schema.
§Examples
use schematron::{Document, Schema};
let schema = Schema::from_str(r#"
<schema xmlns="http://purl.oclc.org/dsdl/schematron">
<pattern>
<rule context="a">
<assert test="b">Needs a b.</assert>
<report test="c">Has a c.</report>
</rule>
</pattern>
</schema>
"#)?;
let report = schema.validate(&Document::from_str("<a><c/></a>")?)?;
// The failed assert is a failure; the successful report is not.
assert_eq!(report.count_failures(), 1);
assert_eq!(report.reports().count(), 1);
assert!(!report.is_valid());Fields§
§title: Option<String>The schema’s title.
phase: Option<String>The phase that ran, when one was named.
schema_version: Option<String>The schema’s @schemaVersion.
namespaces: Vec<Ns>The schema’s namespace bindings, so a consumer can interpret
@location and @test.
patterns: Vec<ActivePattern>The patterns that ran, in order.
Implementations§
Source§impl Report
impl Report
Sourcepub fn to_svrl_with(&self, options: &SvrlOptions) -> String
pub fn to_svrl_with(&self, options: &SvrlOptions) -> String
Renders this report as SVRL.
Source§impl Report
impl Report
Sourcepub fn from_svrl(source: &str) -> Result<Report>
pub fn from_svrl(source: &str) -> Result<Report>
Parses an SVRL document into a report.
SVRL is flat — active-pattern, fired-rule and the findings are all
siblings — so this rebuilds the tree the writer flattened: each rule
belongs to the most recent pattern, each finding to the most recent
rule.
§Errors
Returns Error::XmlParse if the input is not
well-formed XML, and Error::Schema if it is
not an SVRL document.
§Examples
use schematron::{Document, Report, Schema};
let schema = Schema::from_str(r#"
<schema xmlns="http://purl.oclc.org/dsdl/schematron">
<pattern><rule context="a"><assert test="b">Needs a b.</assert></rule></pattern>
</schema>
"#)?;
let original = schema.validate(&Document::from_str("<a/>")?)?;
let parsed = Report::from_svrl(&original.to_svrl())?;
assert_eq!(parsed.count_failures(), 1);
assert_eq!(parsed.failures().next().unwrap().text, "Needs a b.");Source§impl Report
impl Report
Sourcepub fn to_text(&self) -> String
pub fn to_text(&self) -> String
Renders this report for a person to read.
§Examples
use schematron::{Document, Schema};
let schema = Schema::from_str(r#"
<schema xmlns="http://purl.oclc.org/dsdl/schematron">
<pattern><rule context="a"><assert test="b">Needs a b.</assert></rule></pattern>
</schema>
"#)?;
let report = schema.validate(&Document::from_str("<a/>")?)?;
let text = report.to_text();
assert!(text.contains("Needs a b."));
assert!(text.contains("/a[1]"));Sourcepub fn to_text_with(&self, options: &TextOptions) -> String
pub fn to_text_with(&self, options: &TextOptions) -> String
Renders this report for a person to read, with options.
Source§impl Report
impl Report
Sourcepub fn to_json(&self) -> Result<String, Error>
pub fn to_json(&self) -> Result<String, Error>
Renders this report as JSON.
Unlike SVRL, the JSON keeps the report’s tree structure: patterns contain rules, which contain findings.
§Errors
Returns an error only if serialisation fails, which for this type means an allocation failure.
§Examples
use schematron::{Document, Schema};
let schema = Schema::from_str(r#"
<schema xmlns="http://purl.oclc.org/dsdl/schematron">
<pattern><rule context="a"><assert test="b">Needs a b.</assert></rule></pattern>
</schema>
"#)?;
let report = schema.validate(&Document::from_str("<a/>")?)?;
let json = report.to_json()?;
assert!(json.contains("\"FailedAssert\""));Source§impl Report
impl Report
Sourcepub fn is_valid(&self) -> bool
pub fn is_valid(&self) -> bool
Whether the document satisfied the schema.
True when no assert failed. Successful reports are observations and
do not make a document invalid.
Sourcepub fn assertions(&self) -> impl Iterator<Item = &AssertionResult>
pub fn assertions(&self) -> impl Iterator<Item = &AssertionResult>
Every finding, in the order it was produced.
Sourcepub fn failures(&self) -> impl Iterator<Item = &AssertionResult>
pub fn failures(&self) -> impl Iterator<Item = &AssertionResult>
The failed assertions.
Sourcepub fn reports(&self) -> impl Iterator<Item = &AssertionResult>
pub fn reports(&self) -> impl Iterator<Item = &AssertionResult>
The successful reports.
Sourcepub fn count_failures(&self) -> usize
pub fn count_failures(&self) -> usize
How many assertions failed.
Sourcepub fn with_flag<'a>(
&'a self,
flag: &'a str,
) -> impl Iterator<Item = &'a AssertionResult>
pub fn with_flag<'a>( &'a self, flag: &'a str, ) -> impl Iterator<Item = &'a AssertionResult>
The findings carrying a given @flag.
@flag conventionally holds a severity such as error or warning.
The crate assigns it no meaning; this is how a caller applies its own.
Sourcepub fn fired_rules(&self) -> impl Iterator<Item = &FiredRule>
pub fn fired_rules(&self) -> impl Iterator<Item = &FiredRule>
The rules that fired, across every pattern.
Sourcepub fn count_fired_rules(&self) -> usize
pub fn count_fired_rules(&self) -> usize
How many rules fired.
A count of zero on a non-empty document almost always means no rule
context matched anything — most often a missing ns prefix binding.