Expand description
A pure-Rust implementation of RELAX NG.
Structs§
- Compiled
Schema - A parsed schema after composition/simplification (RELAX NG spec §4):
include/div/combineresolved, nestedgrammars flattened, every pattern reduced to the handful of primitive forms the validator understands. Produced bysimplify(orcrate::Schema::compile, which also parses); pass it tocrate::validate(orcrate::Schema::validate) to check documents against it. - Datatype
Context - The in-scope XML namespace prefix bindings at the point a value occurs
in the document (not the schema) — needed to resolve
QName/NOTATION-typed values, whose lexical form (prefix:local) only denotes a value together with a prefix-to-URI binding. Built once per element fromcrate::Element::namespace_bindings. - Datatype
Error - The schema uses a
datatypeLibrary/type/parameter thisDatatypeRegistrycan’t handle. - Datatype
Registry - Maps
datatypeLibraryURIs toDatatypeLibraryimplementations for onecrate::validatecall. - Expanded
Name - An expanded (namespace-resolved) name: local name plus an optional
namespace URI.
Nonemeans “no namespace” — the caller’s document implementation is responsible for resolving any prefixes itself (this crate has no XML/namespace parser of its own). - Parse
Error - A schema’s text isn’t well-formed RELAX NG in its declared
SchemaSyntax— malformed XML/compact-syntax tokens, an unknown element/attribute, a structural violation the syntax layer itself checks (wrong child count, anattribute/startwith more than one pattern child, …). - Resolve
Error - A
SchemaResolverfailed to resolve anhref. - Schema
- A parsed and composed (“simplified”, in RELAX NG spec terms) schema, ready to validate any number of documents against.
- Schema
Document - A parsed (but not yet composed/simplified) RELAX NG schema, as returned
by
crate::parse. Pass it tocrate::simplify(or usecrate::Schema::compile, which does both steps) to get acrate::CompiledSchemaready to validate documents against. - Schema
Error - A schema parsed without error but invalid once composed/simplified —
an undefined
ref, illegal recursion, a duplicatedefinewith inconsistentcombine, a §7 restriction violation, and so on. - Schema
Source - Schema text plus enough context (a base URI, and which syntax it’s
written in) to parse it and resolve any
include/externalRefit contains. This crate never reads files or network resources itself — callers supply schema text directly, and aSchemaResolverfor anything the schema references byhref. - Validation
Error - A single validation problem, with the path of element names from the
document root down to (and including) the element it occurred on, and
an optional location if
Element::locationprovided one.
Enums§
- Compile
Error - Either step
Schema::compileperforms can fail on its own:sourcemight not even parse (malformed.rnc/.rngsyntax —ParseError), or it might parse but fail composition (an undefinedref, illegal recursion, a §7 restriction violation, … —SchemaError). - Content
- One child of an element, in document order. Comments and processing
instructions are not part of this model — a correct
Elementimplementation simply never yields them here. - Schema
Syntax - Which of RELAX NG’s two equivalent syntaxes a
SchemaSource’s text is written in. - Validation
Error Kind - What kind of problem a
ValidationErrordescribes.
Constants§
- XSD_
DATATYPE_ LIBRARY - The namespace URI identifying the XSD datatype library, as used in
datatypeLibrary="..."— seeplan/DECISIONS.md.
Traits§
- Datatype
Library - A
datatypeLibraryimplementation: recognizes a set of type names, each with its own applicable parameters (facets, in XSD’s terminology). - Element
- The minimal view of a document element this crate needs to validate it. Implement this over whatever tree type the caller already has — no document is parsed by this crate itself.
- Schema
Resolver - Resolves an
include/externalRefhref(relative to a base URI) to theSchemaSourceit names. This crate has no file-system or network access of its own — implement this over whatever loading mechanism (files, an in-memory map, HTTP, …) fits the caller, with whatever security boundary (allowed schemes, path restrictions) is appropriate there.
Functions§
- parse
- Parses
source’s text (in its declaredSchemaSyntax) into aSchemaDocument— this step alone doesn’t resolveinclude/externalRefor check most of RELAX NG’s composition-time restrictions; pass the result tocrate::simplifyfor that (or usecrate::Schema::compile, which does both steps). - simplify
- Composes and simplifies
document(RELAX NG spec §4) into aCompiledSchema, resolving anyinclude/externalRefit uses viaresolver. Seecrate::Schema::compilefor a convenience wrapper that also parses. - validate
- Validates
rootagainstschemausingregistryto checkdata/valuepatterns. Returns the list of problems found (empty means valid) — or, if the schema uses adatatypeLibrary/type/parameterregistrydoesn’t recognize, aDatatypeErrorinstead of attempting validation at all, since we can’t know whether the document would pass a check we can’t perform.