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<TResolver> Parser<TResolver>
impl<TResolver> Parser<TResolver>
Sourcepub fn with_default_resolver(self) -> Parser<FileResolver>
pub fn with_default_resolver(self) -> Parser<FileResolver>
Set the default resolver for this parser.
The default resolver is just a simple FileResolver
.
Sourcepub fn with_resolver<XResolver: Resolver + 'static>(
self,
resolver: XResolver,
) -> Parser<XResolver>
pub fn with_resolver<XResolver: Resolver + 'static>( self, resolver: XResolver, ) -> Parser<XResolver>
Set a custom defined resolver for this parser.
Sourcepub fn resolve_includes(self, value: bool) -> Self
pub fn resolve_includes(self, value: bool) -> Self
Enable or disable resolving includes of parsed XML schemas.
Source§impl<TResolver> Parser<TResolver>where
TResolver: Resolver,
impl<TResolver> Parser<TResolver>where
TResolver: Resolver,
Sourcepub fn with_default_namespaces(self) -> Self
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
.
Sourcepub fn with_namespace(
self,
prefix: NamespacePrefix,
namespace: Namespace,
) -> Self
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>
impl<TResolver> Parser<TResolver>
Sourcepub fn add_schema_from_reader<R: BufRead>(
self,
reader: R,
) -> Result<Self, Error<TResolver::Error>>
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.
Sourcepub fn add_schema_from_file<P: AsRef<Path> + Debug>(
self,
path: P,
) -> Result<Self, Error<TResolver::Error>>
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.
Sourcepub fn add_schema_from_files<I>(
self,
paths: I,
) -> Result<Self, Error<TResolver::Error>>
pub fn add_schema_from_files<I>( self, paths: I, ) -> Result<Self, Error<TResolver::Error>>
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.
Sourcepub fn add_schema_from_url(
self,
url: Url,
) -> Result<Self, Error<TResolver::Error>>
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.