ddn.data.xml.xsd

XML Schema (XSD) support (phased).

This module provides a minimal, native XSD representation and validator.

Current scope (phased native subset):

  • Supports a single global xs:element name='root' ....
  • Supports:
  • type='xs:string' (no element children)
  • xs:complexType/xs:sequence of child xs:element with minOccurs/maxOccurs
  • xs:attribute with use='required' or optional
  • Validates:
  • root element name
  • required attributes
  • child element order and occurrence constraints for simple sequences

For broader schema coverage, keep using the CLI oracle (xmllint --schema) while this native implementation is extended.

Types 10

XSD built-in type supported by this module.

STRING`xs:string`
BOOLEAN`xs:boolean`
INT`xs:int`
DECIMAL`xs:decimal`
INTEGER`xs:integer`
NON_NEGATIVE_INTEGER`xs:nonNegativeInteger`
POSITIVE_INTEGER`xs:positiveInteger`
NON_POSITIVE_INTEGER`xs:nonPositiveInteger`
NEGATIVE_INTEGER`xs:negativeInteger`
LONG`xs:long`
SHORT`xs:short`
BYTE`xs:byte`

XSD whiteSpace facet values.

PRESERVE
REPLACE
COLLAPSE
structXsdFacets

XSD facets supported by this module.

Fields
bool hasMinLength
size_t minLength
bool hasMaxLength
size_t maxLength
bool hasMinInclusive
double minInclusive
bool hasMaxInclusive
double maxInclusive
XsdWhiteSpace whiteSpace
string pattern

A simple type declaration.

Fields
XsdFacets facets

XSD particle kind.

ELEMENT
SEQUENCE
CHOICE
ALL

An XSD particle (element, sequence, choice, or all).

Fields
size_t minOccurs
size_t maxOccurs
string nameElement name (for `ELEMENT` kind).
XsdSimpleType typeSimple type of the element (for `ELEMENT` kind).
XsdParticle[] childrenChild particles (for `SEQUENCE`, `CHOICE`, `ALL`).

An attribute declaration.

Fields
string name
bool required
XsdSimpleType typeAttribute simple type (default: `xs:string`).
structXsdSchema

Minimal schema model.

Fields
string rootElementNameGlobal element name.
XsdBuiltinType rootTypeRoot element type.
XsdFacets rootFacetsRoot element facets (used when `rootParticle` is empty).
XsdParticle rootParticleRoot content model particle.
XsdAttributeDecl[] attributesDeclared attributes on the root element.

Result of validating a document against an XSD.

Fields
bool valid`true` if valid.
string messageOptional message if invalid.

Options controlling XSD parsing.

Fields
string[] catalogFilesXML Catalog files used to resolve `schemaLocation` values (system-id mapping).
bool allowNetworkIf `true`, allow loading non-file URI schemas via `networkLoader`.
const(ubyte)[] delegate(string uri) @safe networkLoaderOptional loader for non-file URI schemas (used when `allowNetwork=true`).
bool cacheResourcesIf `true`, cache loaded schema bytes by resolved identifier.
size_t maxDepthMaximum include/import recursion depth.
size_t maxBytesMaximum schema bytes (0 = default).

Functions 15

private fnXsdBuiltinType parseBuiltinType(string qname) @safe
private fnsize_t parseOccurs(string value, bool allowUnbounded, string what) @safe
fnXsdSchema parseXsd(string xsdXml) @safeParses an XSD schema document.
private fnstring normalizeXsdWhiteSpace(string s, XsdWhiteSpace mode) @safe
private fnbool validateSimpleValue(XsdSimpleType t, string value, out string errorMessage) @safe
private fnstring elementTextValue(XmlElement el) @safe
fnXsdSchema parseXsdFromFile(string xsdFile, XsdParseOptions options = XsdParseOptions.init) @safeParses an XSD schema from a file, resolving `xs:include` and `xs:import`.
private fnstring resolveSchemaLocationWithCatalogs( string schemaLocation, string baseSystemId, const string[] catalogFiles) @safe
private fnXsdSchema parseXsdWithIncludes( string xsdXml, string baseSystemId, XsdParseOptions options, size_t depth, ref XmlResourceLoader loader) @safe
fnXsdValidationResult validateXsdDocument(XmlDocument doc, XsdSchema schema) @safeValidates `doc` against `schema`.
private fnXsdValidationResult validateParticle(const ref XsdParticle p, XmlElement[] children, ref size_t pos) @safe

Variables 2

private enumvarXSD_NS = "http://www.w3.org/2001/XMLSchema"
private enumvarUNBOUNDED = size_t.max