pub struct Schema { /* private fields */ }Expand description
A loaded schema set: every component reachable from the entry points.
Implementations§
Source§impl Schema
impl Schema
Sourcepub fn documents(&self) -> &[String]
pub fn documents(&self) -> &[String]
The paths of the schema documents the set was loaded from.
Sourcepub fn omitted_imports(&self) -> &[OmittedImport]
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.
Sourcepub fn global_element_count(&self) -> usize
pub fn global_element_count(&self) -> usize
The number of global element declarations.
Sourcepub fn type_count(&self) -> usize
pub fn type_count(&self) -> usize
The number of type definitions, built-in and anonymous included.
Source§impl Schema
impl Schema
Sourcepub fn load(
files: &[(&str, &str)],
entry_points: &[&str],
) -> Result<Self, LoadError>
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.
Sourcepub fn ubl_2_1() -> Result<Self, LoadError>
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.
Sourcepub fn cii_d16b() -> Result<Self, LoadError>
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.
Sourcepub fn validate(&self, xml: &str) -> Result<Report, DocumentError>
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.
Sourcepub fn validation<'a>(&self, text: &'a str) -> Validation<'_, 'a>
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");Sourcepub fn validate_bytes(&self, bytes: &[u8]) -> Result<Report, DocumentError>
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.