ddn.data.xml.internal.dtd

Internal: DTD parsing, content model representation, and matching.

This module provides the internal DTD data structures, content model parsing into a tree representation, and content model matching used by the DTD validation pipeline.

This module is not part of the public API and may change at any time.

Types 14

Kind of attribute default declaration.

NONENo default semantics (unspecified).
REQUIRED`#REQUIRED`
IMPLIED`#IMPLIED`
FIXED`#FIXED "..."`
DEFAULTA literal default value.

Attribute type in a DTD.

Covers the standard XML 1.0/1.1 attribute types: CDATA, ID, IDREF, IDREFS, NMTOKEN, NMTOKENS, ENTITY, ENTITIES, NOTATION, and ENUMERATION.

All attribute types are validated during DTD validation. Lexical validity checks use the ASCII subset of the XML Name and Nmtoken productions.

UNKNOWNUnknown/unspecified type.
CDATA`CDATA`
ID`ID`
IDREF`IDREF`
IDREFS`IDREFS`
NMTOKEN`NMTOKEN`
NMTOKENS`NMTOKENS`
ENTITY`ENTITY`
ENTITIES`ENTITIES`
NOTATION`NOTATION`
ENUMERATIONEnumerated type (a fixed set of values).

A DTD general entity declaration.

Fields
string nameEntity name (without `&` and `;`).
string valueReplacement text for internal entities (decoded later).
bool isParameterTrue if this is a parameter entity (`%name;`).

A DTD element declaration.

This stores a raw content model string for now.

Fields
string nameElement name.
string contentModelRaw content model (e.g. `EMPTY`, `ANY`, or parenthesized model).

A DTD attribute declaration.

Fields
string elementNameElement name to which this attribute declaration applies.
string nameAttribute name.
XmlDtdAttributeType typeAttribute type.
string[] enumerationEnumerated values (only meaningful for `ENUMERATION`/`NOTATION`).
XmlDtdAttributeDefaultKind defaultKindDefault kind.
string defaultValueDefault value (for `DEFAULT`/`FIXED`).

A DTD notation declaration.

Fields
string nameNotation name.
string systemIdOptional system identifier.
string publicIdOptional public identifier.

A DTD unparsed entity declaration (NDATA).

Fields
string nameEntity name.
string systemIdOptional system identifier.
string publicIdOptional public identifier.
string notationNameNotation name referenced by `NDATA`.
structXmlDtd

In-memory representation of a DTD.

Stores entity, element, attribute, notation, and unparsed entity declarations collected from internal and external DTD subsets. Used by the DTD validation pipeline for element model checking, attribute validation, and ID/IDREF consistency enforcement.

Fields
private XmlDtdEntityDecl[string] _entities
private XmlDtdElementDecl[string] _elements
private XmlDtdNotationDecl[string] _notations
private XmlDtdUnparsedEntityDecl[string] _unparsedEntities
private XmlDtdAttributeDecl[][string] _attributesByElement
Methods
void defineEntity(string name, string value, bool isParameter = false) @safeDefines a general entity if not already declared.
const(XmlDtdEntityDecl) * findEntity(string name) const @safe nothrowLooks up an entity.
void defineElement(string name, string contentModel) @safeDefines an element declaration if not already declared.
const(XmlDtdElementDecl) * findElement(string name) const @safe nothrowLooks up an element declaration.
void defineNotation(string name, string systemId = "", string publicId = "") @safeDefines a notation if not already declared.
const(XmlDtdNotationDecl) * findNotation(string name) const @safe nothrowLooks up a notation.
void defineUnparsedEntity(string name, string systemId, string publicId, string notationName) @safeDefines (or redefines) an unparsed entity.
const(XmlDtdUnparsedEntityDecl) * findUnparsedEntity(string name) const @safe nothrowLooks up an unparsed entity.
XmlDtdUnparsedEntityDecl[] unparsedEntities() const @safeReturns all unparsed entity declarations in deterministic (name-sorted) order.
XmlDtdNotationDecl[] notations() const @safeReturns all notation declarations in deterministic (name-sorted) order.
void addAttributeDecl(XmlDtdAttributeDecl decl) @safeAdds an attribute declaration.
const(XmlDtdAttributeDecl)[] attributeDeclsFor(string elementName) const @safe nothrowReturns attribute declarations for `elementName`.

Kind of DTD content model node.

ELEMENTA named element.
SEQUENCEA sequence of children (all must appear in order).
CHOICEA choice of children (exactly one must appear).

Occurrence indicator for content model nodes.

ONCEExactly one.
OPTIONALZero or one (`?`).
ZERO_OR_MOREZero or more (`*`).
ONE_OR_MOREOne or more (`+`).

A parsed DTD content model node.

Represents either a named element or a group (sequence/choice) with an occurrence indicator.

Fields
ContentModelKind kindKind of this node.
string nameElement name (only meaningful for `ELEMENT` kind).
ContentModelNode[] childrenChild nodes (only meaningful for `SEQUENCE`/`CHOICE` kinds).
ContentModelOccurrence occurrenceOccurrence indicator.

Represents a parsed DTD content model.

This can be EMPTY, ANY, mixed content (#PCDATA-based), or an element-content model.

Fields
bool isEmptyTrue if the model is `EMPTY`.
bool isAnyTrue if the model is `ANY`.
bool isMixedTrue if the model is mixed content (starts with `#PCDATA`).
bool[string] mixedElementsFor mixed content, the set of allowed element names (may be empty).
ContentModelNode rootFor element-content models, the root of the content model tree.
bool validTrue if the model was parsed successfully.
string errorMessageError message if parsing failed.
private structParseGroupResult
Fields
bool valid
string errorMessage
bool isMixed
bool[string] mixedElements

Result of content model matching.

Fields
bool matchesTrue if the content matches the model.
string errorMessageError message if matching failed.

Functions 15

fnParsedContentModel parseContentModel(string model) @safeParses a DTD content model string into a structured representation.
private fnParseGroupResult parseContentModelGroup(string model, ref size_t pos) @safe
private fnParseGroupResult parseMixedContent(string model, ref size_t pos) @safe
private fnvoid skipWhitespace(string s, ref size_t pos) @safe nothrow
private fnbool isNameChar(char c) @safe nothrow
private fnstring posToString(size_t pos) @safe
fnContentModelMatchResult matchContentModel( const ref ParsedContentModel model, const(string)[] childElements, bool hasText) @safeMatches a sequence of child element names against a parsed content model.
private fnbool matchNode(const ref ContentModelNode node, const(string)[] children, ref size_t pos) @safe
private fnbool matchElement(const ref ContentModelNode node, const(string)[] children, ref size_t pos) @safe
private fnbool matchSequence(const ref ContentModelNode node, const(string)[] children, ref size_t pos) @safe
private fnbool matchChoice(const ref ContentModelNode node, const(string)[] children, ref size_t pos) @safe
fnbool isNameStartChar(char c) @safe nothrow pureReturns `true` if `c` is an XML 1.0 NameStartChar (ASCII subset).
fnbool isNameCharFull(char c) @safe nothrow pureReturns `true` if `c` is an XML 1.0 NameChar (ASCII subset).
fnbool isValidXmlName(string s) @safe nothrow pureReturns `true` if `s` is a valid XML 1.0 `Name` (ASCII subset).
fnbool isValidNmToken(string s) @safe nothrow pureReturns `true` if `s` is a valid XML 1.0 `Nmtoken` (ASCII subset).