Skip to main content

Crate relax_ng

Crate relax_ng 

Source
Expand description

A pure-Rust implementation of RELAX NG.

Structs§

CompiledSchema
A parsed schema after composition/simplification (RELAX NG spec §4): include/div/combine resolved, nested grammars flattened, every pattern reduced to the handful of primitive forms the validator understands. Produced by simplify (or crate::Schema::compile, which also parses); pass it to crate::validate (or crate::Schema::validate) to check documents against it.
DatatypeContext
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 from crate::Element::namespace_bindings.
DatatypeError
The schema uses a datatypeLibrary/type/parameter this DatatypeRegistry can’t handle.
DatatypeRegistry
Maps datatypeLibrary URIs to DatatypeLibrary implementations for one crate::validate call.
ExpandedName
An expanded (namespace-resolved) name: local name plus an optional namespace URI. None means “no namespace” — the caller’s document implementation is responsible for resolving any prefixes itself (this crate has no XML/namespace parser of its own).
ParseError
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, an attribute/start with more than one pattern child, …).
ResolveError
A SchemaResolver failed to resolve an href.
Schema
A parsed and composed (“simplified”, in RELAX NG spec terms) schema, ready to validate any number of documents against.
SchemaDocument
A parsed (but not yet composed/simplified) RELAX NG schema, as returned by crate::parse. Pass it to crate::simplify (or use crate::Schema::compile, which does both steps) to get a crate::CompiledSchema ready to validate documents against.
SchemaError
A schema parsed without error but invalid once composed/simplified — an undefined ref, illegal recursion, a duplicate define with inconsistent combine, a §7 restriction violation, and so on.
SchemaSource
Schema text plus enough context (a base URI, and which syntax it’s written in) to parse it and resolve any include/externalRef it contains. This crate never reads files or network resources itself — callers supply schema text directly, and a SchemaResolver for anything the schema references by href.
ValidationError
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::location provided one.

Enums§

CompileError
Either step Schema::compile performs can fail on its own: source might not even parse (malformed .rnc/.rng syntax — ParseError), or it might parse but fail composition (an undefined ref, 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 Element implementation simply never yields them here.
SchemaSyntax
Which of RELAX NG’s two equivalent syntaxes a SchemaSource’s text is written in.
ValidationErrorKind
What kind of problem a ValidationError describes.

Constants§

XSD_DATATYPE_LIBRARY
The namespace URI identifying the XSD datatype library, as used in datatypeLibrary="..." — see plan/DECISIONS.md.

Traits§

DatatypeLibrary
A datatypeLibrary implementation: 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.
SchemaResolver
Resolves an include/externalRef href (relative to a base URI) to the SchemaSource it 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 declared SchemaSyntax) into a SchemaDocument — this step alone doesn’t resolve include/ externalRef or check most of RELAX NG’s composition-time restrictions; pass the result to crate::simplify for that (or use crate::Schema::compile, which does both steps).
simplify
Composes and simplifies document (RELAX NG spec §4) into a CompiledSchema, resolving any include/externalRef it uses via resolver. See crate::Schema::compile for a convenience wrapper that also parses.
validate
Validates root against schema using registry to check data/ value patterns. Returns the list of problems found (empty means valid) — or, if the schema uses a datatypeLibrary/type/parameter registry doesn’t recognize, a DatatypeError instead of attempting validation at all, since we can’t know whether the document would pass a check we can’t perform.