Struct Parser

Source
pub struct Parser<TResolver = NoOpResolver> { /* private fields */ }
Expand description

The Parser is responsible for loading and parsing XML Schema documents into a structured Schemas representation.

It supports resolution of schema references such as <import> and <include> using a pluggable Resolver, and can read schema content from strings, files, or URLs.

Internally, the parser maintains a queue of pending schema loads and a cache to prevent duplicate resolutions. Once all schemas are processed, the finish method returns the final Schemas collection.

A generic resolver type TResolver controls how external schemas are fetched. By default, a no-op resolver is used, but file-based or custom resolvers can be injected using with_resolver.

Implementations§

Source§

impl Parser

Source

pub fn new() -> Self

Create a new Parser instance.

Source§

impl<TResolver> Parser<TResolver>

Source

pub fn with_default_resolver(self) -> Parser<FileResolver>

Set the default resolver for this parser.

The default resolver is just a simple FileResolver.

Source

pub fn with_resolver<XResolver: Resolver + 'static>( self, resolver: XResolver, ) -> Parser<XResolver>

Set a custom defined resolver for this parser.

Source

pub fn resolve_includes(self, value: bool) -> Self

Enable or disable resolving includes of parsed XML schemas.

Source

pub fn finish(self) -> Schemas

Finish the parsing process by returning the generated Schemas instance containing all parsed schemas.

Source§

impl<TResolver> Parser<TResolver>
where TResolver: Resolver,

Source

pub fn with_default_namespaces(self) -> Self

Add the default namespaces to this parser.

The default namespaces are:

§Errors

Forwards the errors from with_namespace.

Source

pub fn with_namespace( self, prefix: NamespacePrefix, namespace: Namespace, ) -> Self

Add a new namespace to this parser.

This method will add a new namespace to the parser. This can be useful to pre-heat the prefixes for known namespace, or to define namespaces for custom defined types.

This will not add any schema information. It’s just a namespace definition.

§Errors

Will return an error if a problem or mismatch with the already existing namespaces was encountered.

Source§

impl<TResolver> Parser<TResolver>
where TResolver: Resolver, TResolver::Buffer: BufRead,

Source

pub fn add_schema_from_str( self, schema: &str, ) -> Result<Self, Error<TResolver::Error>>

Add a new XML schema from the passed string.

This will parse the XML schema represented by the provided string and add all schema information to the resulting Schemas structure.

§Errors

Will return an suitable error if the parser could not parse the provided schema.

Source

pub fn add_schema_from_reader<R: BufRead>( self, reader: R, ) -> Result<Self, Error<TResolver::Error>>

Add a new XML schema from the passed reader.

This will parse the XML schema represented by the provided reader and add all schema information to the resulting Schemas structure.

§Errors

Will return an suitable error if the parser could not read the data from the reader, or parse the schema provided by the reader.

Source

pub fn add_schema_from_file<P: AsRef<Path> + Debug>( self, path: P, ) -> Result<Self, Error<TResolver::Error>>

Add a new XML schema from the passed file path.

This will parse the XML schema represented by the provided filepath and add all schema information to the resulting Schemas structure.

§Errors

Will return an suitable error if the parser could not read the data from the file, or parse the schema content.

Source

pub fn add_schema_from_files<I>( self, paths: I, ) -> Result<Self, Error<TResolver::Error>>
where I: IntoIterator + Debug, I::Item: AsRef<Path> + Debug,

Add multiple XML schemas from the passed paths iterator.

§Errors

Will return an suitable error if the parser could not read the data from any file, or parse the schema content.

Source

pub fn add_schema_from_url( self, url: Url, ) -> Result<Self, Error<TResolver::Error>>

Add a new XML schema from the passed file url.

This will parse the XML schema represented by the provided url and add all schema information to the resulting Schemas structure.

§Errors

Will return an suitable error if the parser could not resolve the URL using the provided resolver or the data from the resolver could not be parsed.

Trait Implementations§

Source§

impl<TResolver: Debug> Debug for Parser<TResolver>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<TResolver: Default> Default for Parser<TResolver>

Source§

fn default() -> Parser<TResolver>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<TResolver> Freeze for Parser<TResolver>
where TResolver: Freeze,

§

impl<TResolver> RefUnwindSafe for Parser<TResolver>
where TResolver: RefUnwindSafe,

§

impl<TResolver> Send for Parser<TResolver>
where TResolver: Send,

§

impl<TResolver> Sync for Parser<TResolver>
where TResolver: Sync,

§

impl<TResolver> Unpin for Parser<TResolver>
where TResolver: Unpin,

§

impl<TResolver> UnwindSafe for Parser<TResolver>
where TResolver: UnwindSafe,

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<X> AsAny for X
where X: 'static,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Get a reference to the current object as Any.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Get a mutable reference to the current object as Any.
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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T