1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// SPDX-License-Identifier: MIT OR Apache-2.0
// Copyright (c) 2026 xmlschema. All rights reserved.
//! Schema documents the caller supplies, for `xs:import` and
//! `xs:include`.
//!
//! Neither this crate nor `oxml` performs I/O. A schema referencing
//! another names a *location*, and resolving it is the caller's
//! decision -- they have the permission model, the user, and the
//! context to make it. A schema processor that fetches by default is
//! how a validator becomes an outbound request.
//!
//! So [`parse_schema`] resolves nothing and reports every `xs:import`
//! and `xs:include` as unenforceable. [`parse_schema_with`] takes a
//! [`SchemaSource`] and asks it, by `schemaLocation`, for the
//! documents it needs.
//!
//! [`parse_schema`]: crate::parse_schema
//! [`parse_schema_with`]: crate::parse_schema_with
/// Somewhere the caller can look up a schema document.
///
/// Implemented for `&[(&str, &str)]`, which is enough for a test
/// fixture or a set of schemas already in memory.
///
/// # Examples
///
/// ```
/// use xmlschema::{SchemaSource, parse_schema_with, validate};
///
/// let common = r#"<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
/// <xs:simpleType name="code">
/// <xs:restriction base="xs:string">
/// <xs:maxLength value="4"/>
/// </xs:restriction>
/// </xs:simpleType>
/// </xs:schema>"#;
///
/// let main = r#"<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
/// <xs:include schemaLocation="common.xsd"/>
/// <xs:element name="r" type="code"/>
/// </xs:schema>"#;
///
/// let parts: &[(&str, &str)] = &[("common.xsd", common)];
/// assert_eq!(parts.fetch("common.xsd"), Some(common));
///
/// let schema = parse_schema_with(main, &parts)?;
/// let doc = oxml::parse("<r>abcd</r>")?;
/// assert!(validate(&doc, &schema).is_valid());
///
/// // The included type is enforced, which is the whole point.
/// let too_long = oxml::parse("<r>abcde</r>")?;
/// assert!(!validate(&too_long, &schema).is_valid());
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
/// A source that supplies nothing, which is what [`parse_schema`] uses.
///
/// [`parse_schema`]: crate::parse_schema
;