einvoice_xsd/lib.rs
1//! XML Schema 1.0 validation of UBL 2.1 Invoice and `CreditNote` documents against the
2//! official OASIS UBL 2.1 schemas, and of UN/CEFACT Cross Industry Invoice D16B
3//! documents against the official UN/CEFACT CII D16B schemas, in pure Rust.
4//!
5//! This is not a general XML Schema processor: it implements exactly the constructs
6//! that the schemas reachable from `UBL-Invoice-2.1.xsd` and `UBL-CreditNote-2.1.xsd`
7//! use (see the inventory below), and those that the schemas of the Cross Industry
8//! Invoice family add (see [CII-family schemas](#cii-family-schemas)), and refuses any
9//! other construct when a schema set is loaded ([`LoadErrorKind::Unsupported`]), so
10//! that a schema it cannot handle is never half-checked.
11//!
12//! ```
13//! let schema = einvoice_xsd::Schema::ubl_2_1()?;
14//! let report = schema.validate(
15//! r#"<CreditNote xmlns="urn:oasis:names:specification:ubl:schema:xsd:CreditNote-2"
16//! xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2">
17//! <cbc:ID>CN-1</cbc:ID><cbc:IssueDate>2024-02-30</cbc:IssueDate>
18//! </CreditNote>"#,
19//! )?;
20//! // Sorted by the position of the element concerned: the incomplete CreditNote
21//! // first, then its invalid date.
22//! let kinds: Vec<&str> = report.errors.iter().map(|e| e.kind.as_str()).collect();
23//! assert_eq!(kinds, ["missing-element", "invalid-value"]);
24//! assert_eq!((report.errors[1].line, report.errors[1].element.as_str()), (3, "{urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2}IssueDate"));
25//! # Ok::<(), Box<dyn std::error::Error>>(())
26//! ```
27//!
28//! # Schemas
29//!
30//! Thirteen of the fifteen schema documents reachable from the two entry points are
31//! vendored byte for byte in `schemas/oasis-ubl-2.1/` and embedded
32//! ([`UBL_2_1_FILES`]); [`Schema::ubl_2_1`] loads both entry points into one schema
33//! set, as an XML Schema processor given both does. [`Schema::load`] loads any set of
34//! schema documents within the supported subset, from memory: `xs:import` and
35//! `xs:include` are resolved as paths relative to the importing document, never
36//! fetched.
37//!
38//! The UN/CEFACT CII D16B schemas with uncoupled code lists (D16B SCRDM (Subset),
39//! the schemas the CEN EN 16931 CII validation artefacts are built against) are
40//! vendored byte for byte in `schemas/uncefact-cii-d16b/` and embedded
41//! ([`CII_D16B_FILES`]): the entry point `CrossIndustryInvoice_100pD16B.xsd` and the
42//! three modules it imports, its qualified and unqualified data types and its
43//! reusable aggregates. Those import no code-list module: code values are checked
44//! by the CEN rules, not by the schema. [`Schema::cii_d16b`] loads them.
45//!
46//! The other two are the ETSI `XAdES` schemas (`UBL-XAdESv132-2.1.xsd` and
47//! `UBL-XAdESv141-2.1.xsd`), which the OASIS package includes but no licence allows
48//! to redistribute, so they are not shipped. Their two namespaces
49//! ([`XADES_NAMESPACES`]) are the only ones whose import may be left out: an
50//! `xs:import` of one of them whose document is not in the set is not loaded, and is
51//! listed by [`Schema::omitted_imports`]; any other missing document is a
52//! [`LoadErrorKind::MissingFile`] error. The UBL schemas only import these
53//! namespaces and never refer to their components, so `XAdES` elements can only occur
54//! where a lax wildcard allows them (in `ext:ExtensionContent` and in `ds:Object`,
55//! where a `XAdES` signature puts its `xades:QualifyingProperties`): without the
56//! schemas they have no declaration and are validated laxly, as `xs:anyType`. Their
57//! content models, values and attributes are then not checked; their descendants that
58//! have a global declaration (`ds:DigestMethod`, `cbc:` elements, ...) still are. A
59//! user who has the two files can add them to the embedded ones and load the
60//! complete set with [`Schema::load`]: they are then loaded and validated strictly.
61//!
62//! # Validation
63//!
64//! [`Schema::validate`] reads the document in one pass of the streaming reader of
65//! [`einvoice_xml`] (namespace-aware, no external resources), without building a tree,
66//! so that the memory it uses grows with the depth of the document rather than its size;
67//! a document with a document type declaration, which that reader refuses, is parsed
68//! with `roxmltree` instead (internal DTD subset allowed for entities).
69//! [`Schema::validation`] is the same validation for a caller that reads the document
70//! itself and gives it the reader's events. Either returns a [`Report`] listing
71//! every validity error with a stable [`ErrorKind`], the line and column of the
72//! element concerned and a message. The document element must match a global element
73//! declaration of the set. Validation follows XML Schema 1.0 Second Edition:
74//!
75//! * content models are compiled to deterministic automata (Unique Particle
76//! Attribution is checked at load); `minOccurs`/`maxOccurs` on elements,
77//! sequences, choices and wildcards;
78//! * wildcards: `##any` and `##other`, `processContents` `strict`, `lax` and `skip`.
79//! Lax content without a declaration is validated as `xs:anyType`, whose own
80//! content is lax: an element anywhere below that has a global declaration (for
81//! instance a `cbc:` element inside `ext:ExtensionContent`) is validated against it;
82//! * attributes: declared uses (`required`/`optional`), attribute wildcards, the
83//! four `xsi:` attributes (`xsi:type` with derivation checks and abstract types,
84//! `xsi:nil` refused since no declaration is nillable, `xsi:schemaLocation` and
85//! `xsi:noNamespaceSchemaLocation` ignored as hints);
86//! * simple values: whitespace processing and the lexical space of every built-in
87//! simple type of XML Schema 1.0 (those the schemas use, and any a document names in
88//! `xsi:type`: the integer types with their bounds, `float`, `double`, `duration`,
89//! the `g*` types, `hexBinary`, `QName` with its prefix declared, `NMTOKEN`,
90//! `IDREF`, `ENTITY`, `NOTATION` and the list types), the `enumeration`,
91//! `minLength` and `maxLength` facets (lengths in characters, after whitespace
92//! processing, for the types derived from `xs:string`), uniqueness of `xs:ID`
93//! values, and every `xs:IDREF` value matching an `xs:ID` of the document (Part 1
94//! 3.3.4, which libxml2 does not check); an `xs:ENTITY` value is invalid, a
95//! document without a document type declaration having no unparsed entity, and so
96//! is an `xs:NOTATION`, the schemas declaring no notation;
97//! * value constraints (`default` and `fixed`) of element and attribute
98//! declarations: a fixed value is compared with the value of the element or
99//! attribute in the value space of its type (cvc-elt.5.2.2, cvc-attribute.4), so
100//! that `1.5` matches a fixed `1.50` of an `xs:decimal` and `1` a fixed `true` of
101//! an `xs:boolean`; an element with no character or element children takes its
102//! declaration's default or fixed value, which is then valid (cvc-elt.5.1; with
103//! `xsi:type`, it must be valid for the actual type). This crate reports validity
104//! only and does not build the post-schema-validation infoset, so defaults are not
105//! added to the document: an absent attribute with a default, or an empty element,
106//! is simply valid.
107//!
108//! The decimal and integer types have no digit limit, dates follow the XML Schema
109//! 1.0 rules (no year zero, at least four year digits, timezones up to ±14:00,
110//! `24:00:00` as end of day), `anyURI` is checked as XML Schema 1.0 defines it
111//! (escaping per `XLink` 1.0 section 5.4, then RFC 2396 as amended by RFC 2732).
112//!
113//! # CII-family schemas
114//!
115//! [`Schema::load`] also loads the schema sets of the UN/CEFACT Cross Industry
116//! Invoice: CII D16B (the schemas of the CEN EN 16931 CII validation artefacts,
117//! with and without the coupled code lists), CII D22B (with and without code lists),
118//! and the five Factur-X (`ZUGFeRD`) profiles. Of these, only CII D16B with uncoupled
119//! code lists is shipped with this crate ([`Schema::cii_d16b`]); the CII D22B
120//! schemas carry no licence notice that allows their redistribution. Over the UBL
121//! subset, they need:
122//!
123//! * `fixed` and `default` on `xs:attribute` (D16B, D22B, Factur-X EXTENDED);
124//! * anonymous `xs:complexType` in local element declarations (every set has some:
125//! the `DateTimeString`, `DateString` or `IndicatorString` elements of the data
126//! types, with simple content); any content the subset supports is accepted
127//! there (simple, element-only, mixed or empty);
128//! * `minLength` and `maxLength` on restrictions of `xs:token` (D16B and D22B);
129//! * `enumeration` on restrictions of `xs:token`, imports of the code-list schemas
130//! and finite `maxOccurs` above one (already in the subset).
131//!
132//! `fixed` and `default` on `xs:element` are supported the same way, although none
133//! of these schemas use them. What stays outside the subset, refused when the schema
134//! is loaded: anonymous simple types, anonymous complex types in global element
135//! declarations, a fixed value of a date or time type (comparing such values is not
136//! implemented; a default one is supported), a value constraint on an element with
137//! mixed content, the length facets on `xs:anyURI` and `xs:base64Binary`, the
138//! `length` facet, facets with `fixed="true"`, and a restriction redeclaring an
139//! attribute that has a fixed value in its base type.
140//!
141//! # Comparison with xmllint
142//!
143//! The test suite compares every verdict with xmllint (libxml2 2.9.14), which loads
144//! the complete OASIS schema set (`XAdES` schemas included), on the CEN EN 16931 UBL
145//! test corpus and on synthetic mutations covering each construct (`tests/oracle/`).
146//! Every corpus case agrees. The other differences are listed with their cause in
147//! `tests/oracle/disagreements.tsv`: the cases where xmllint departs from XML Schema
148//! 1.0 and this crate does not, and the cases with `XAdES` content, which this crate
149//! validates laxly with the shipped schemas. The `xmllint-oracle` example also runs
150//! this crate with the complete set, where the second kind does not occur.
151//!
152//! A second suite does the same on a synthetic schema set in the style of the CII
153//! schemas (`tests/oracle/synthetic/`), covering value constraints, length facets
154//! and anonymous complex types, with mutations of its documents and of the schemas
155//! themselves (whether the edited set loads). Its listed differences are cases where
156//! libxml2 departs from XML Schema 1.0 (it compares the text of an element with a
157//! fixed value as a string, before whitespace processing, rather than its value;
158//! it accepts length facets that contradict each other), cases with more errors
159//! reported by libxml2 for the same verdict, and constructs refused as unsupported.
160//!
161//! A third suite compares [`Schema::cii_d16b`] with xmllint loading the same four
162//! documents, on every case of the CEN EN 16931 CII test corpus and every one of its
163//! mutation cases (`tests/oracle/cii/`). Every corpus case agrees; the mutation
164//! cases that do not are listed with their cause (decimals beyond libxml2's 24
165//! digits, a document deeper than libxml2's parser accepts, a second error reported
166//! by libxml2 for content already invalid). The same comparison runs locally on the
167//! CII corpora of the fetched rule sets (XRechnung, Factur-X, the French rules) when
168//! they are built.
169//!
170//! # Licences
171//!
172//! The code is MIT; the embedded schemas keep the terms stated in their own headers
173//! (OASIS and UN/CEFACT for the UBL 2.1 schemas, W3C for the XML Signature schema
174//! they include, UN/CEFACT for the CII D16B schemas). [`LICENCES`] holds the full
175//! text of each, as shipped in the crate's `LICENSES/` directory, for programs that
176//! must show them to their users.
177//!
178//! # Inventory of the UBL 2.1 schemas
179//!
180//! Counted over the thirteen vendored documents by the `inventory` test, which fails
181//! when this table no longer matches them. Annotations are not descended into.
182//!
183//! In short: 13 schema documents, all with `elementFormDefault="qualified"`; 22
184//! `xs:import` (two of them, of the `XAdES` namespaces, not loaded) and one
185//! `xs:include` (the extension content type, included by the common extension
186//! components); 1,581 global element declarations and 1,168 named complex types;
187//! content models made of `xs:sequence` and `xs:choice` of element references, local
188//! elements and wildcards, with `minOccurs` 0 or 1 and `maxOccurs` 1 or `unbounded`
189//! only. There are no anonymous types, no groups or attribute groups, no substitution
190//! groups, no identity constraints, no default or fixed values, no `xs:all`, no lists
191//! or unions, and no facets.
192//!
193//! * The UBL extension point: `ext:UBLExtensions` holds one or more `ext:UBLExtension`,
194//! each ending with `ext:ExtensionContent`, whose type is a sequence of exactly one
195//! `xs:any namespace="##other" processContents="lax"` (`##other` relative to the
196//! extension components namespace, so neither that namespace nor no namespace).
197//! The signature extension (`sig:UBLDocumentSignatures`) is declared and imported,
198//! so it is validated strictly; any other extension content is validated laxly.
199//! * The CCTS core component types (`CCTS_CCT_SchemaModule-2.1.xsd`) are complex types
200//! with simple content extending `xs:decimal`, `xs:base64Binary`,
201//! `xs:normalizedString` and `xs:string` with optional supplementary-component
202//! attributes; the unqualified data types extend them (or `xs:date`, `xs:dateTime`,
203//! `xs:time`, `xs:boolean`), and seven of them are simple-content restrictions
204//! making one attribute required (`currencyID`, `mimeCode`, `unitCode`). Every
205//! `cbc:` type extends one of these.
206//! * The W3C XML Signature schema brings the rest: mixed content, nested and
207//! repeated choices and sequences, strict and lax wildcards, `xs:ID` attributes,
208//! local elements typed directly with built-in types, and the three simple types
209//! (restrictions of `xs:base64Binary` twice and of `xs:integer`).
210//!
211//! The supported subset also covers what the two `XAdES` schemas add, so that the
212//! complete OASIS set loads: an attribute wildcard (`xs:anyAttribute`, strict), an
213//! abstract type with two complex-content restrictions, and a simple type
214//! restricting `xs:string` with the `enumeration` facet.
215//!
216//! INVENTORY-START
217//! | Construct | Count |
218//! |---|---:|
219//! | `built-in type xs:ID` | 9 |
220//! | `built-in type xs:anyURI` | 15 |
221//! | `built-in type xs:base64Binary` | 11 |
222//! | `built-in type xs:boolean` | 1 |
223//! | `built-in type xs:date` | 1 |
224//! | `built-in type xs:dateTime` | 1 |
225//! | `built-in type xs:decimal` | 4 |
226//! | `built-in type xs:integer` | 2 |
227//! | `built-in type xs:language` | 2 |
228//! | `built-in type xs:normalizedString` | 26 |
229//! | `built-in type xs:string` | 20 |
230//! | `built-in type xs:time` | 1 |
231//! | `xs:annotation` | 2566 |
232//! | `xs:any` | 13 |
233//! | `xs:any @maxOccurs="1"` | 1 |
234//! | `xs:any @maxOccurs="unbounded"` | 5 |
235//! | `xs:any @minOccurs="0"` | 6 |
236//! | `xs:any @minOccurs="1"` | 1 |
237//! | `xs:any @namespace="##any"` | 2 |
238//! | `xs:any @namespace="##other"` | 11 |
239//! | `xs:any @processContents="lax"` | 11 |
240//! | `xs:attribute` | 62 |
241//! | `xs:attribute @use="optional"` | 49 |
242//! | `xs:attribute @use="required"` | 12 |
243//! | `xs:choice` | 6 |
244//! | `xs:choice @maxOccurs="unbounded"` | 3 |
245//! | `xs:choice @minOccurs="0"` | 1 |
246//! | `xs:complexType` | 1168 |
247//! | `xs:complexType @mixed="true"` | 8 |
248//! | `xs:element (global)` | 1581 |
249//! | `xs:element (local, name)` | 22 |
250//! | `xs:element (local, name) @minOccurs="0"` | 4 |
251//! | `xs:element (local, ref)` | 2278 |
252//! | `xs:element (local, ref) @maxOccurs="1"` | 1657 |
253//! | `xs:element (local, ref) @maxOccurs="unbounded"` | 603 |
254//! | `xs:element (local, ref) @minOccurs="0"` | 2026 |
255//! | `xs:element (local, ref) @minOccurs="1"` | 233 |
256//! | `xs:extension (in xs:simpleContent)` | 905 |
257//! | `xs:import` | 22 |
258//! | `xs:import @namespace="http://uri.etsi.org/01903/v1.3.2#"` | 1 |
259//! | `xs:import @namespace="http://uri.etsi.org/01903/v1.4.1#"` | 1 |
260//! | `xs:import @namespace="http://www.w3.org/2000/09/xmldsig#"` | 1 |
261//! | `xs:import @namespace="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"` | 2 |
262//! | `xs:import @namespace="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"` | 5 |
263//! | `xs:import @namespace="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2"` | 2 |
264//! | `xs:import @namespace="urn:oasis:names:specification:ubl:schema:xsd:CommonSignatureComponents-2"` | 1 |
265//! | `xs:import @namespace="urn:oasis:names:specification:ubl:schema:xsd:QualifiedDataTypes-2"` | 2 |
266//! | `xs:import @namespace="urn:oasis:names:specification:ubl:schema:xsd:SignatureAggregateComponents-2"` | 1 |
267//! | `xs:import @namespace="urn:oasis:names:specification:ubl:schema:xsd:SignatureBasicComponents-2"` | 1 |
268//! | `xs:import @namespace="urn:oasis:names:specification:ubl:schema:xsd:UnqualifiedDataTypes-2"` | 4 |
269//! | `xs:import @namespace="urn:un:unece:uncefact:data:specification:CoreComponentTypeSchemaModule:2"` | 1 |
270//! | `xs:include` | 1 |
271//! | `xs:restriction (in xs:simpleContent)` | 7 |
272//! | `xs:restriction (in xs:simpleType)` | 3 |
273//! | `xs:schema` | 13 |
274//! | `xs:schema @attributeFormDefault="unqualified"` | 12 |
275//! | `xs:schema @elementFormDefault="qualified"` | 13 |
276//! | `xs:sequence` | 255 |
277//! | `xs:sequence @maxOccurs="unbounded"` | 3 |
278//! | `xs:sequence @minOccurs="0"` | 3 |
279//! | `xs:simpleContent` | 912 |
280//! | `xs:simpleType` | 3 |
281//! INVENTORY-END
282
283mod automaton;
284mod cii;
285mod datatypes;
286mod error;
287mod licences;
288mod load;
289mod model;
290mod ubl;
291mod uri;
292mod validate;
293
294pub use cii::{CII_D16B_ENTRY_POINT, CII_D16B_FILES};
295pub use datatypes::Builtin;
296pub use error::{DocumentError, ErrorKind, LoadError, LoadErrorKind, Report, ValidationError};
297pub use licences::{LICENCES, Licence};
298pub use model::{OmittedImport, Schema};
299pub use ubl::{CREDIT_NOTE_ENTRY_POINT, INVOICE_ENTRY_POINT, UBL_2_1_FILES, XADES_NAMESPACES};
300pub use validate::Validation;
301
302impl Schema {
303 /// Loads a schema set from memory. `files` maps paths (relative,
304 /// `/`-separated) to the text of each schema document; `entry_points` are the
305 /// paths to start from. Every document reachable through `xs:import` and
306 /// `xs:include` must be in `files`, except that of an import of one of
307 /// [`XADES_NAMESPACES`], which is then not loaded ([`Schema::omitted_imports`]).
308 ///
309 /// # Errors
310 ///
311 /// A [`LoadError`]: a missing or malformed document, a construct outside the
312 /// supported subset, or an incorrect schema.
313 pub fn load(files: &[(&str, &str)], entry_points: &[&str]) -> Result<Self, LoadError> {
314 load::load(files, entry_points)
315 }
316
317 /// Loads the embedded OASIS UBL 2.1 schemas, with both entry points
318 /// ([`INVOICE_ENTRY_POINT`] and [`CREDIT_NOTE_ENTRY_POINT`]). The two imports
319 /// of the `XAdES` namespaces are not loaded ([`Schema::omitted_imports`]):
320 /// `XAdES` content is validated laxly.
321 ///
322 /// # Errors
323 ///
324 /// None in practice: the embedded schemas are within the supported subset (a
325 /// test loads them). The error is returned rather than hidden.
326 pub fn ubl_2_1() -> Result<Self, LoadError> {
327 Self::load(
328 UBL_2_1_FILES,
329 &[INVOICE_ENTRY_POINT, CREDIT_NOTE_ENTRY_POINT],
330 )
331 }
332
333 /// Loads the embedded UN/CEFACT Cross Industry Invoice D16B schemas (uncoupled
334 /// code lists, the schemas of the CEN EN 16931 CII validation artefacts), from
335 /// their entry point [`CII_D16B_ENTRY_POINT`]: the four documents of
336 /// [`CII_D16B_FILES`], no import omitted.
337 ///
338 /// ```
339 /// let schema = einvoice_xsd::Schema::cii_d16b()?;
340 /// let report = schema.validate(
341 /// r#"<rsm:CrossIndustryInvoice xmlns:rsm="urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100"/>"#,
342 /// )?;
343 /// // The exchanged document context and the rest are missing.
344 /// assert_eq!(report.errors[0].kind.as_str(), "missing-element");
345 /// # Ok::<(), Box<dyn std::error::Error>>(())
346 /// ```
347 ///
348 /// # Errors
349 ///
350 /// None in practice: the embedded schemas are within the supported subset (a
351 /// test loads them). The error is returned rather than hidden.
352 pub fn cii_d16b() -> Result<Self, LoadError> {
353 Self::load(CII_D16B_FILES, &[CII_D16B_ENTRY_POINT])
354 }
355
356 /// Validates a document, in one pass of the streaming reader of the `einvoice-xml`
357 /// crate over the text (no tree is built). A document with a document type
358 /// declaration, which that reader refuses, is read with `roxmltree` instead (the
359 /// entities of its internal subset expanded, attribute defaults not applied).
360 ///
361 /// # Errors
362 ///
363 /// [`DocumentError::Malformed`] when the text is not well-formed XML with
364 /// namespaces, wherever the error is (it comes before the others);
365 /// [`DocumentError::Unsupported`] when the document needs a feature outside the
366 /// implemented subset (an `xs:ENTITY` value in a document with a document type declaration, whose
367 /// unparsed entities this crate does not read, or a value constraint of a
368 /// declaration taken as a value of a type valid only in a context).
369 /// Validity errors are not errors: they are in the [`Report`].
370 pub fn validate(&self, xml: &str) -> Result<Report, DocumentError> {
371 validate::validate(self, xml)
372 }
373
374 /// A validation of `text` to be given its events, read by the caller with an
375 /// [`einvoice_xml::Reader`] of `text`: for a caller that checks the document
376 /// otherwise in the same pass (its depth, ...). [`Schema::validate`] is this
377 /// validation given every event of the reader, the reader's errors being
378 /// [`DocumentError::Malformed`].
379 ///
380 /// ```
381 /// use einvoice_xml::Reader;
382 ///
383 /// let schema = einvoice_xsd::Schema::ubl_2_1()?;
384 /// let text = r#"<Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"/>"#;
385 /// let mut validation = schema.validation(text);
386 /// let mut reader = Reader::new(text);
387 /// while let Some(event) = reader.next_event()? {
388 /// validation.event(event);
389 /// }
390 /// let report = validation.finish()?;
391 /// assert_eq!(report, schema.validate(text)?);
392 /// assert_eq!(report.errors[0].kind.as_str(), "missing-element");
393 /// # Ok::<(), Box<dyn std::error::Error>>(())
394 /// ```
395 #[must_use]
396 pub fn validation<'a>(&self, text: &'a str) -> Validation<'_, 'a> {
397 Validation::new(self, text)
398 }
399
400 /// Validates a document given as bytes, in any encoding that
401 /// [`einvoice_xml::decode`] reads (UTF-8, UTF-16, US-ASCII, ISO-8859-1, ISO-8859-15,
402 /// windows-1252), as its byte order mark, first bytes and XML declaration say.
403 ///
404 /// # Errors
405 ///
406 /// As [`Schema::validate`]; also [`DocumentError::Unsupported`] for another
407 /// encoding, and [`DocumentError::Malformed`] for bytes that are not a character of
408 /// the encoding or first bytes and an XML declaration that disagree.
409 pub fn validate_bytes(&self, bytes: &[u8]) -> Result<Report, DocumentError> {
410 let text = einvoice_xml::decode(bytes).map_err(|e| match e {
411 einvoice_xml::Error::UnsupportedEncoding(name) => DocumentError::Unsupported {
412 line: 1,
413 column: 1,
414 message: format!("the {name} encoding"),
415 },
416 e => DocumentError::Malformed {
417 line: e.pos().row,
418 column: e.pos().col,
419 message: e.to_string(),
420 },
421 })?;
422 self.validate(&text)
423 }
424}