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:sequenceof childxs:elementwithminOccurs/maxOccursxs:attributewithuse='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
enumXsdBuiltinType
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`
enumXsdWhiteSpace
XSD whiteSpace facet values.
PRESERVE
REPLACE
COLLAPSE
structXsdFacets
XSD facets supported by this module.
Fields
bool hasMinLengthsize_t minLengthbool hasMaxLengthsize_t maxLengthbool hasMinInclusivedouble minInclusivebool hasMaxInclusivedouble maxInclusiveXsdWhiteSpace whiteSpacestring patternstructXsdSimpleType
A simple type declaration.
enumXsdParticleKind
XSD particle kind.
ELEMENT
SEQUENCE
CHOICE
ALL
structXsdParticle
An XSD particle (element, sequence, choice, or all).
Fields
XsdParticleKind kindsize_t minOccurssize_t maxOccursstring nameElement name (for `ELEMENT` kind).XsdSimpleType typeSimple type of the element (for `ELEMENT` kind).XsdParticle[] childrenChild particles (for `SEQUENCE`, `CHOICE`, `ALL`).structXsdAttributeDecl
An attribute declaration.
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.structXsdValidationResult
Result of validating a document against an XSD.
Fields
bool valid`true` if valid.string messageOptional message if invalid.structXsdParseOptions
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
fn
XsdSchema parseXsdFromFile(string xsdFile, XsdParseOptions options = XsdParseOptions.init) @safeParses an XSD schema from a file, resolving `xs:include` and `xs:import`.private fn
string resolveSchemaLocationWithCatalogs(
string schemaLocation,
string baseSystemId,
const string[] catalogFiles) @safeprivate fn
XsdSchema parseXsdWithIncludes(
string xsdXml,
string baseSystemId,
XsdParseOptions options,
size_t depth,
ref XmlResourceLoader loader) @safefn
XsdValidationResult validateXsdDocument(XmlDocument doc, XsdSchema schema) @safeValidates `doc` against `schema`.private fn
XsdValidationResult validateParticle(const ref XsdParticle p, XmlElement[] children, ref size_t pos) @safeVariables 2
private enumvar
XSD_NS = "http://www.w3.org/2001/XMLSchema"private enumvar
UNBOUNDED = size_t.max