Skip to main content

SchemaSetBuilder

Struct SchemaSetBuilder 

Source
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

Source

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.

Source

pub fn with_config(config: ResolverConfig) -> Self

Create builder with custom resolver configuration.

Source

pub fn with_loader(loader: Box<dyn SchemaLoader>) -> Self

Create builder with custom loader.

Source

pub fn with_version(version: XsdVersion) -> Self

Create a builder configured for a specific XSD version.

Source

pub fn xsd11() -> Self

Create a builder configured for XSD 1.1.

Source

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.

Source

pub fn xsd11_with_loader(loader: Box<dyn SchemaLoader>) -> Self

Create a builder configured for XSD 1.1 with a custom schema loader.

Source

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()?;
Source

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);
Source

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.

Source

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.

Source

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 string
  • base_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);
Source

pub fn add_bytes(self, xml: &[u8], base_uri: &str) -> SchemaResult<Self>

Add a schema from bytes.

§Arguments
  • xml - The schema XML content as bytes
  • base_uri - Base URI for resolving relative references
Source

pub fn schema_count(&self) -> usize

Get the number of schemas added so far.

Source

pub fn is_loaded(&self, location: &str) -> bool

Check if a schema location has already been loaded.

Source

pub fn compile(self) -> SchemaResult<CompiledSchemaSet>

Compile all added schemas.

This performs the following phases:

  1. Directive Resolution - Process include/import/redefine/override directives
  2. Redefine/Override Application - Apply component replacements
  3. Inline Type Assembly - Materialize inline type definitions
  4. Reference Resolution - Resolve QName references to component keys
  5. 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.)

Trait Implementations§

Source§

impl Default for SchemaSetBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. 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> ErasedDestructor for T
where T: 'static,

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> MaybeSendSync for T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.