ddn.data.xml.xsd

XML Schema (XSD) 1.0 validation.

This module provides a native XSD representation and validator.

Supported schema features:

  • Global xs:element declarations (multiple) with name and type
  • Global named xs:complexType and xs:simpleType with type references
  • xs:element ref='...' and xs:attribute ref='...' references
  • xs:complexType with xs:sequence, xs:choice, xs:all content models
  • xs:attribute with use='required' or optional, with type references
  • xs:group name='...' and xs:group ref='...' model group definitions
  • xs:attributeGroup name='...' and xs:attributeGroup ref='...'
  • xs:extension base='...' in xs:complexContent (basic derivation)
  • xs:restriction base='...' in xs:simpleContent and xs:simpleType
  • xs:include and xs:import with XML Catalog support
  • minOccurs/maxOccurs occurrence constraints (including unbounded)
  • xs:any wildcard (lax processing with sequence look-ahead)
  • targetNamespace with elementFormDefault/attributeFormDefault awareness

Supported facets:

  • xs:minLength, xs:maxLength, xs:length (string-length constraints)
  • xs:minInclusive, xs:maxInclusive (inclusive range bounds)
  • xs:minExclusive, xs:maxExclusive (exclusive range bounds)
  • xs:totalDigits (maximum number of decimal digits)
  • xs:fractionDigits (maximum number of fractional digits)
  • xs:pattern (regex pattern; multiple patterns are ORed)
  • xs:whiteSpace (preserve, replace, collapse)
  • xs:enumeration (value must match one of the listed values)

Supported built-in types:

  • String types: xs:string, xs:normalizedString, xs:token, xs:language, xs:NMTOKEN, xs:NMTOKENS, xs:ID, xs:IDREF, xs:anyURI, xs:anySimpleType
  • Numeric types: xs:decimal, xs:float, xs:double
  • Integer types: xs:integer, xs:int, xs:long, xs:short, xs:byte, xs:nonNegativeInteger, xs:positiveInteger, xs:nonPositiveInteger, xs:negativeInteger, xs:unsignedInt, xs:unsignedLong, xs:unsignedShort, xs:unsignedByte
  • xs:boolean
  • Date/time types: xs:date, xs:dateTime, xs:time

Remaining limitations:

  • xs:key/xs:keyref identity constraints are not supported
  • xs:unique identity constraints are not supported
  • xs:assert/xs:assertion (XSD 1.1) are not supported
  • xs:redefine is not supported
  • xs:notation is not supported
  • xs:union/xs:list simple type composition is not supported
  • Namespace-qualified element/attribute resolution is lexical-only
  • xs:complexType mixed='true' is acknowledged but not enforced
  • xs:any namespace attribute is acknowledged but not filtered
  • block/final attributes on types/elements are not enforced
  • xs:date/xs:dateTime/xs:time validation is structural (format-only)

Types 15

XSD built-in type supported by this module.

STRING`xs:string`
BOOLEAN`xs:boolean`
DECIMAL`xs:decimal`
FLOAT`xs:float`
DOUBLE`xs:double`
INT`xs:int`
INTEGER`xs:integer`
LONG`xs:long`
SHORT`xs:short`
BYTE`xs:byte`
NON_NEGATIVE_INTEGER`xs:nonNegativeInteger`
POSITIVE_INTEGER`xs:positiveInteger`
NON_POSITIVE_INTEGER`xs:nonPositiveInteger`
NEGATIVE_INTEGER`xs:negativeInteger`
UNSIGNED_INT`xs:unsignedInt`
UNSIGNED_LONG`xs:unsignedLong`
UNSIGNED_SHORT`xs:unsignedShort`
UNSIGNED_BYTE`xs:unsignedByte`
DATE`xs:date`
DATETIME`xs:dateTime`
TIME`xs:time`
ANY_URI`xs:anyURI`
ANY_SIMPLE_TYPE`xs:anySimpleType`
TOKEN`xs:token`
NORMALIZED_STRING`xs:normalizedString`
NMTOKEN`xs:NMTOKEN`
NMTOKENS`xs:NMTOKENS`
ID`xs:ID`
IDREF`xs:IDREF`
LANGUAGE`xs:language`

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 hasLength
size_t length_
bool hasMinInclusive
double minInclusive
bool hasMaxInclusive
double maxInclusive
bool hasMinExclusive
double minExclusive
bool hasMaxExclusive
double maxExclusive
bool hasTotalDigits
size_t totalDigits
bool hasFractionDigits
size_t fractionDigits
XsdWhiteSpace whiteSpace
string pattern
string[] enumerationEnumeration values (from xs:enumeration facets).

A simple type declaration.

Fields
XsdFacets facets

XSD particle kind.

ELEMENT
SEQUENCE
CHOICE
ALL
ANY

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

Fields
size_t minOccurs
size_t maxOccurs
string nameElement name (for `ELEMENT` kind).
string refNameElement ref name (when `ref=` is used instead of `name=`).
XsdSimpleType typeSimple type of the element (for `ELEMENT` kind).
XsdParticle[] childrenChild particles (for `SEQUENCE`, `CHOICE`, `ALL`).
XsdAttributeDecl[] attributesAttributes for inline complex content.

An attribute declaration.

Fields
string name
bool required
string refNameAttribute ref name (when `ref=` is used).
XsdSimpleType typeAttribute simple type (default: `xs:string`).
structXsdSchema

Minimal schema model.

Fields
XsdElementDecl[] elementsGlobal element declarations indexed by name.
XsdComplexType[string] complexTypesGlobal named complex types.
XsdSimpleType[string] simpleTypesGlobal named simple types.
XsdGroup[string] groupsGlobal named model groups.
XsdAttributeGroup[string] attributeGroupsGlobal named attribute groups.
string targetNamespaceTarget namespace.
bool elementFormDefaultQualifiedelementFormDefault: 'qualified' or 'unqualified'.
bool attributeFormDefaultQualifiedattributeFormDefault: 'qualified' or 'unqualified'.

A global element declaration.

Fields
string nameElement name.
XsdBuiltinType builtinTypeElement type (if simple).
string typeNameNamed type reference (e.g. 'myType').
XsdParticle particleInline content model (if complex).
XsdFacets facetsInline facets (when simple content).
XsdAttributeDecl[] attributesAttributes declared on this element.
bool hasComplexContentWhether the type was resolved from a named complexType.
bool hasInlineContentWhether this element has inline content (not a type reference).

A named complex type.

Fields
XsdParticle particleContent model particle.
XsdAttributeDecl[] attributesAttributes.
string extensionBaseExtension base type name.
bool usesExtensionWhether this uses extension.
bool mixedWhether mixed content is allowed.
structXsdGroup

A named model group.

Fields
XsdParticle particleGroup content particle.

A named attribute group.

Fields
XsdAttributeDecl[] attributesAttributes in this group.

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 28

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 fnbool isBuiltinType(string qname) @safe pure
private fnstring normalizeXsdWhiteSpace(string s, XsdWhiteSpace mode) @safe
private fnbool validateSimpleValue(XsdSimpleType t, string value, out string errorMessage) @safe
private fnbool validateStringFacets(string v, ref XsdFacets facets, out string errorMessage) @safe
private fnbool validateNumericFacets(double n, XsdSimpleType t, out string errorMessage) @safe
private fnbool isValidDate(string v) @safe pure
private fnbool isValidTime(string v) @safe pure
private fnbool isValidDateTime(string v) @safe pure
private fnbool isValidLanguage(string v) @safe pure
private fnbool isNmtokenChars(string v) @safe pure
private fnbool isNameStartChar(dchar c) @safe pure
private fnbool isNameChar(dchar c) @safe pure
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`.

Variables 2

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