Skip to main content

Schema

Struct Schema 

Source
pub struct Schema { /* private fields */ }
Expand description

The top-level compiled schema. Cheap to clone (one Arc bump).

All names are fully resolved at this point; the validator looks up types and elements by QName.

Implementations§

Source§

impl Schema

Source

pub fn compile_str(xsd: &str) -> Result<Schema, SchemaCompileError>

Compile a schema from a single XSD source string. Equivalent to compile_with using a NoResolver — any <xs:import> or <xs:include> directive is rejected.

Source

pub fn compile_str_with_options( xsd: &str, options: SchemaOptions, ) -> Result<Schema, SchemaCompileError>

Compile a schema with explicit SchemaOptions (the version knob today; more options may land here). The resolver is NoResolver — imports / includes are rejected.

Source

pub fn compile_with<R: SchemaResolver>( xsd: &str, resolver: R, ) -> Result<Schema, SchemaCompileError>

Compile a schema, resolving any <xs:import> / <xs:include> / <xs:redefine> directives via the supplied SchemaResolver.

Cycles are detected (a schema importing one that already loaded is silently skipped); recursion is bounded at 64 levels deep.

Source

pub fn compile_with_options<R: SchemaResolver>( xsd: &str, resolver: R, options: SchemaOptions, ) -> Result<Schema, SchemaCompileError>

Compile a schema with both a SchemaResolver and explicit SchemaOptions. This is the most general entry point; the others all delegate here.

Source

pub fn compile_file( path: impl AsRef<Path>, ) -> Result<Schema, SchemaCompileError>

Compile a schema from a file on disk, with relative-path resolution of <xs:import> and <xs:include> against the schema’s own directory.

Equivalent to:

let dir = path.parent().unwrap_or_else(|| Path::new("."));
Schema::compile_with(&fs::read_to_string(path)?, FsResolver::new(dir))
Source§

impl Schema

Source

pub fn element(&self, name: &QName) -> Option<&Arc<ElementDecl>>

Look up a top-level element by qualified name.

Source

pub fn attribute(&self, name: &QName) -> Option<&Arc<AttributeDecl>>

Look up a top-level attribute by qualified name.

Source

pub fn type_def(&self, name: &QName) -> Option<&TypeRef>

Look up a top-level type by qualified name. Returns None for types not declared in this schema (callers handle built-ins via the BuiltinType lookup).

Source

pub fn target_namespace(&self) -> Option<&str>

Source

pub fn elements(&self) -> impl Iterator<Item = (&QName, &Arc<ElementDecl>)>

Iterate every top-level element. Useful for instance validation to find a candidate root type.

Source

pub fn types(&self) -> impl Iterator<Item = (&QName, &TypeRef)>

Iterate every top-level type definition.

Source

pub fn substitutes_for(&self, head: &QName) -> &[Arc<ElementDecl>]

Substitution-group members for a given head, if any. Empty when no element substitutes for this head.

Source§

impl Schema

Source

pub fn validate_str(&self, xml: &str) -> Result<(), ValidationError>

Source

pub fn validate_bytes(&self, xml: &[u8]) -> Result<(), ValidationError>

Source

pub fn validate_str_opts( &self, xml: &str, opts: ValidationOptions, ) -> Result<(), ValidationError>

Source

pub fn validate_doc(&self, doc: &Document) -> Result<(), ValidationError>

Validate an already-parsed Document directly, without going through XML re-serialisation.

Equivalent to serialising the document and calling validate_str, but skips that round-trip — useful when the document came from parse_str or process_xincludes and you’d otherwise burn a second parse pass.

Diagnostic positioning trade-off: source byte offsets aren’t available from a Document (the original bytes are gone), so reported issues carry line: None / column: None instead of the precise positions you’d get from validate_str. Element paths (/catalog/book[3]) are reported the same either way.

Source

pub fn validate_doc_opts( &self, doc: &Document, opts: ValidationOptions, ) -> Result<(), ValidationError>

As validate_doc, but honours an explicit ValidationOptions.

Source

pub fn validate_doc_typed( &self, doc: &Document, ) -> (Result<(), ValidationError>, PsviTypes)

As validate_doc, but also returns PsviTypes — a per-node map of the schema type that governed each element during validation.

This is the post-schema-validation infoset entry point that schema-aware XPath/XSLT processing builds on (typed atomization, instance of element(*, T), data()). The returned table is keyed by the addresses of doc’s nodes, so it is only valid while doc is alive. Validation errors are reported in the Result exactly as validate_doc reports them; the annotations are returned regardless, so a caller that wants best-effort typing of a partially-valid document can ignore the Result.

Trait Implementations§

Source§

impl Clone for Schema

Source§

fn clone(&self) -> Schema

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Schema

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.