pub struct SchemaSetBuilder { /* private fields */ }Expand description
Builder for creating compiled schema sets.
Implements the C# XmlSchemaSet pattern where schemas are added first, then compiled together as a group.
§Example
use xsd_schema::SchemaSetBuilder;
let compiled = SchemaSetBuilder::new()
.add_source(r#"<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="root" type="xs:string"/>
</xs:schema>"#, "inline.xsd")
.expect("parse failed")
.compile()
.expect("compile failed");
assert_eq!(compiled.stats.documents_loaded, 1);Implementations§
Source§impl SchemaSetBuilder
impl SchemaSetBuilder
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new builder with default configuration.
Uses the default loader chain (embedded + filesystem) and automatically adds the XML catalog for well-known namespaces.
Sourcepub fn with_config(config: ResolverConfig) -> Self
pub fn with_config(config: ResolverConfig) -> Self
Create builder with custom resolver configuration.
Sourcepub fn with_loader(loader: Box<dyn SchemaLoader>) -> Self
pub fn with_loader(loader: Box<dyn SchemaLoader>) -> Self
Create builder with custom loader.
Sourcepub fn with_version(version: XsdVersion) -> Self
pub fn with_version(version: XsdVersion) -> Self
Create a builder configured for a specific XSD version.
Sourcepub fn set_regex_compatibility(&mut self, compat: RegexCompat) -> &mut Self
pub fn set_regex_compatibility(&mut self, compat: RegexCompat) -> &mut Self
Set the regex compatibility mode on the underlying schema set.
Affects how pattern facets in subsequently added/compiled schemas
are validated. See RegexCompat and doc/INTRODUCTION.md for
the closed list of leniencies enabled by LenientMs. Default is
RegexCompat::Strict.
Sourcepub fn xsd11_with_loader(loader: Box<dyn SchemaLoader>) -> Self
pub fn xsd11_with_loader(loader: Box<dyn SchemaLoader>) -> Self
Create a builder configured for XSD 1.1 with a custom schema loader.
Sourcepub fn add_from(&mut self, schema_set: &SchemaSet) -> &mut Self
pub fn add_from(&mut self, schema_set: &SchemaSet) -> &mut Self
Re-load all schemas from an existing compiled schema set.
Iterates the loaded locations in schema_set and adds each one to
this builder. This lets you seed a new builder from a previously
compiled set without manually tracking the original file paths —
useful for enriching with xsi:schemaLocation hints.
Locations that fail to load (e.g. inline sources without a file path) are silently skipped. Already-loaded locations are deduplicated.
§Example
let mut builder = SchemaSetBuilder::new();
builder.add_from(&original_schema_set);
load_hints_into_builder(&mut builder, &sl_hints, &nnsl_hints);
let enriched = builder.compile()?;Sourcepub fn add(self, _namespace: &str, location: &str) -> SchemaResult<Self>
pub fn add(self, _namespace: &str, location: &str) -> SchemaResult<Self>
Add a schema by namespace and location.
Matches the C# XmlSchemaSet.Add(namespace, location) pattern.
The namespace parameter is for documentation/validation purposes;
the actual namespace comes from the schema’s targetNamespace attribute.
§Arguments
_namespace- Expected namespace (for documentation; not enforced)location- File path or URI to load the schema from
§Example
use xsd_schema::SchemaSetBuilder;
let builder = SchemaSetBuilder::new()
.add("urn:books", "examples/books.xsd")
.expect("failed to load books.xsd");
assert_eq!(builder.schema_count(), 1);Sourcepub fn try_add(&mut self, location: &str) -> SchemaResult<bool>
pub fn try_add(&mut self, location: &str) -> SchemaResult<bool>
Add a schema by location without consuming the builder.
Returns Ok(true) if the schema was freshly loaded, Ok(false) if
it was already present (dedup). Returns Err on load/parse failure.
The location is first normalized via the resolver so that relative and absolute forms of the same path are correctly deduplicated.
Sourcepub fn try_add_relative(
&mut self,
location: &str,
base_uri: &str,
) -> SchemaResult<bool>
pub fn try_add_relative( &mut self, location: &str, base_uri: &str, ) -> SchemaResult<bool>
Add a schema by resolving a relative location against a base URI.
Uses the builder’s resolver for URI resolution (handles Windows paths, URL normalization, etc.). The resolved absolute URI is used for loading and dedup tracking.
Returns Ok(true) if freshly loaded, Ok(false) if already present.
Sourcepub fn add_source(self, xml: &str, base_uri: &str) -> SchemaResult<Self>
pub fn add_source(self, xml: &str, base_uri: &str) -> SchemaResult<Self>
Add a schema from XML source string.
§Arguments
xml- The schema XML content as a stringbase_uri- Base URI for resolving relative references
§Example
use xsd_schema::SchemaSetBuilder;
let builder = SchemaSetBuilder::new()
.add_source(r#"<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="root" type="xs:string"/>
</xs:schema>"#, "inline.xsd")
.expect("parse failed");
assert_eq!(builder.schema_count(), 1);Sourcepub fn add_bytes(self, xml: &[u8], base_uri: &str) -> SchemaResult<Self>
pub fn add_bytes(self, xml: &[u8], base_uri: &str) -> SchemaResult<Self>
Add a schema from bytes.
§Arguments
xml- The schema XML content as bytesbase_uri- Base URI for resolving relative references
Sourcepub fn schema_count(&self) -> usize
pub fn schema_count(&self) -> usize
Get the number of schemas added so far.
Sourcepub fn is_loaded(&self, location: &str) -> bool
pub fn is_loaded(&self, location: &str) -> bool
Check if a schema location has already been loaded.
Sourcepub fn compile(self) -> SchemaResult<CompiledSchemaSet>
pub fn compile(self) -> SchemaResult<CompiledSchemaSet>
Compile all added schemas.
This performs the following phases:
- Directive Resolution - Process include/import/redefine/override directives
- Redefine/Override Application - Apply component replacements
- Inline Type Assembly - Materialize inline type definitions
- Reference Resolution - Resolve QName references to component keys
- Particle Allocation - Allocate element declarations for content particles
§Returns
A CompiledSchemaSet containing the fully processed schema set and
compilation statistics.
§Errors
Returns an error if any phase fails (invalid schema, missing references, etc.)