pub struct Parser<TResolver = NoOpResolver> { /* private fields */ }
Expand description
The Parser
is used to load and parse XML schema information from different
sources.
This structure can be used to load XML schemas information from different
sources using so called Resolver
s. After the content of a schema was load
is it parsed and added to the list of schemas, managed by this parser.
The resulting Schemas
instance can then be used by an
Interpreter
, to generate the more common
Types
structure out of it.
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_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.