Skip to main content

Schema

Struct Schema 

Source
pub struct Schema { /* private fields */ }
Expand description

A loaded schema set: every component reachable from the entry points.

Implementations§

Source§

impl Schema

Source

pub fn documents(&self) -> &[String]

The paths of the schema documents the set was loaded from.

Source

pub fn omitted_imports(&self) -> &[OmittedImport]

The imports that were not loaded because their namespace is one of XADES_NAMESPACES and the schema document they name is not in the set, in the order they were found. Empty when every import was loaded.

Source

pub fn global_element_count(&self) -> usize

The number of global element declarations.

Source

pub fn type_count(&self) -> usize

The number of type definitions, built-in and anonymous included.

Source§

impl Schema

Source

pub fn load( files: &[(&str, &str)], entry_points: &[&str], ) -> Result<Self, LoadError>

Loads a schema set from memory. files maps paths (relative, /-separated) to the text of each schema document; entry_points are the paths to start from. Every document reachable through xs:import and xs:include must be in files, except that of an import of one of XADES_NAMESPACES, which is then not loaded (Schema::omitted_imports).

§Errors

A LoadError: a missing or malformed document, a construct outside the supported subset, or an incorrect schema.

Source

pub fn ubl_2_1() -> Result<Self, LoadError>

Loads the embedded OASIS UBL 2.1 schemas, with both entry points (INVOICE_ENTRY_POINT and CREDIT_NOTE_ENTRY_POINT). The two imports of the XAdES namespaces are not loaded (Schema::omitted_imports): XAdES content is validated laxly.

§Errors

None in practice: the embedded schemas are within the supported subset (a test loads them). The error is returned rather than hidden.

Source

pub fn cii_d16b() -> Result<Self, LoadError>

Loads the embedded UN/CEFACT Cross Industry Invoice D16B schemas (uncoupled code lists, the schemas of the CEN EN 16931 CII validation artefacts), from their entry point CII_D16B_ENTRY_POINT: the four documents of CII_D16B_FILES, no import omitted.

let schema = einvoice_xsd::Schema::cii_d16b()?;
let report = schema.validate(
    r#"<rsm:CrossIndustryInvoice xmlns:rsm="urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100"/>"#,
)?;
// The exchanged document context and the rest are missing.
assert_eq!(report.errors[0].kind.as_str(), "missing-element");
§Errors

None in practice: the embedded schemas are within the supported subset (a test loads them). The error is returned rather than hidden.

Source

pub fn validate(&self, xml: &str) -> Result<Report, DocumentError>

Validates a document, in one pass of the streaming reader of the einvoice-xml crate over the text (no tree is built). A document with a document type declaration, which that reader refuses, is read with roxmltree instead (the entities of its internal subset expanded, attribute defaults not applied).

§Errors

DocumentError::Malformed when the text is not well-formed XML with namespaces, wherever the error is (it comes before the others); DocumentError::Unsupported when the document needs a feature outside the implemented subset (an xs:ENTITY value in a document with a document type declaration, whose unparsed entities this crate does not read, or a value constraint of a declaration taken as a value of a type valid only in a context). Validity errors are not errors: they are in the Report.

Source

pub fn validation<'a>(&self, text: &'a str) -> Validation<'_, 'a>

A validation of text to be given its events, read by the caller with an einvoice_xml::Reader of text: for a caller that checks the document otherwise in the same pass (its depth, …). Schema::validate is this validation given every event of the reader, the reader’s errors being DocumentError::Malformed.

use einvoice_xml::Reader;

let schema = einvoice_xsd::Schema::ubl_2_1()?;
let text = r#"<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"/>"#;
let mut validation = schema.validation(text);
let mut reader = Reader::new(text);
while let Some(event) = reader.next_event()? {
    validation.event(event);
}
let report = validation.finish()?;
assert_eq!(report, schema.validate(text)?);
assert_eq!(report.errors[0].kind.as_str(), "missing-element");
Source

pub fn validate_bytes(&self, bytes: &[u8]) -> Result<Report, DocumentError>

Validates a document given as bytes, in any encoding that einvoice_xml::decode reads (UTF-8, UTF-16, US-ASCII, ISO-8859-1, ISO-8859-15, windows-1252), as its byte order mark, first bytes and XML declaration say.

§Errors

As Schema::validate; also DocumentError::Unsupported for another encoding, and DocumentError::Malformed for bytes that are not a character of the encoding or first bytes and an XML declaration that disagree.

Trait Implementations§

Source§

impl Clone for Schema

Source§

fn clone(&self) -> Self

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 Schema

Source§

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

Formats the value using the given formatter. Read more

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> 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.