Skip to main content

Report

Struct Report 

Source
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

Source

pub fn to_svrl(&self) -> String

Renders this report as SVRL, with default options.

Source

pub fn to_svrl_with(&self, options: &SvrlOptions) -> String

Renders this report as SVRL.

Source§

impl Report

Source

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

Source

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]"));
Source

pub fn to_text_with(&self, options: &TextOptions) -> String

Renders this report for a person to read, with options.

Source§

impl Report

Source

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

Source

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.

Source

pub fn assertions(&self) -> impl Iterator<Item = &AssertionResult>

Every finding, in the order it was produced.

Source

pub fn failures(&self) -> impl Iterator<Item = &AssertionResult>

The failed assertions.

Source

pub fn reports(&self) -> impl Iterator<Item = &AssertionResult>

The successful reports.

Source

pub fn count_failures(&self) -> usize

How many assertions failed.

Source

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.

Source

pub fn fired_rules(&self) -> impl Iterator<Item = &FiredRule>

The rules that fired, across every pattern.

Source

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.

Trait Implementations§

Source§

impl Clone for Report

Source§

fn clone(&self) -> Report

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Report

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Report

Source§

fn default() -> Report

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Report

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for Report

Source§

impl PartialEq for Report

Source§

fn eq(&self, other: &Report) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Report

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Report

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.