Expand description
DTD validation (§27, §85 Phase 6).
DTD validation against element/attribute declarations:
- Element content model validation — does the element’s child sequence match its declared content model?
- Attribute value validation — does each attribute’s value conform to its declared type (CDATA, ID, IDREF, IDREFS, ENTITY, ENTITIES, NMTOKEN, NMTOKENS, ENUMERATION, NOTATION)?
- ID/IDREF consistency — are all ID values unique? Does each IDREF reference a valid ID?
- Required attributes — are all REQUIRED attributes present?
- NOTATION validation — are NOTATION attributes referencing declared notations?
- Well-formedness constraints — additional validity constraints
§UPSTREAM-PARITY
This module follows libxml2’s valid.c implementation. The validation
context (xmlValidCtxt) accumulates ID/IDREF tables across the document
and checks consistency in xmlValidateDocumentFinal.
§Phase 6 status
Complete — all core DTD validation functions are implemented. Edge-case behavior for degenerate DTDs matches upstream.
Structs§
- Content
Model Exec - Runtime exec state for one open element’s content model.
- Content
Model Nfa - Incremental content-model matcher stored in
_xmlElement.cont_model.
Functions§
- add_id⚠
- Upstream
xmlAddID(ctxt, doc, value, attr)— returns the xmlID or NULL. Reports “ID %s already defined” through the validation context on duplicates and a memory error on OOM. - add_
id_ ⚠safe - Upstream
xmlAddIDSafe(attr, value)(2.13+): add an ID without a validation context. Returns 1 on success, 0 if the ID already exists, -1 on OOM. - add_ref⚠
- Upstream
xmlAddRef(ctxt, doc, value, attr)— registers an IDREF. Returns the xmlRef or NULL. - free_
content_ ⚠model_ nfa - Free a compiled content-model NFA (called from xmlFreeElement).
- free_
id_ ⚠table - Upstream
xmlFreeIDTable(table). - free_
ref_ ⚠table - Upstream
xmlFreeRefTable(table). - free_
valid_ ⚠ctxt - Free a validation context.
- get_
dtd_ ⚠attr_ desc - Upstream
xmlGetDtdAttrDesc(dtd, elem, name)— attribute declaration lookup splitting the attribute QName into (local, prefix). - get_
dtd_ ⚠element_ desc - Upstream
xmlGetDtdElementDesc(dtd, name)— plain element declaration lookup with QName splitting. - get_
dtd_ ⚠notation_ desc - Upstream
xmlGetDtdNotationDesc(dtd, name). - get_
dtd_ ⚠qattr_ desc - Upstream
xmlGetDtdQAttrDesc(dtd, elem, name, prefix)— the attribute declaration table is keyed by (name, prefix, elem). - get_
dtd_ ⚠qelement_ desc - Upstream
xmlGetDtdQElementDesc(dtd, name, prefix). - get_id⚠
- Upstream
xmlGetID(doc, ID): returns the attribute holding the ID, or the document pointer itself when operating on a stream (attribute node no longer exists). - get_
refs ⚠ - Upstream
xmlGetRefs(doc, ID): returns the list of references for an ID. - is_
empty_ ⚠element - Check if an element is declared as EMPTY.
- is_id⚠
- Upstream
xmlIsID(doc, elem, attr): is this attribute an ID? Handles the HTML special cases (id attribute; name attribute on ) and the DTD declaration lookup, plus the xml:id namespace convention. - is_
mixed_ ⚠element - Check if an element has a mixed content model.
- is_ref⚠
- Upstream
xmlIsRef(doc, elem, attr): is this attribute an IDREF? - new_
valid_ ⚠ctxt - Create a new validation context.
- remove_
id ⚠ - Upstream
xmlRemoveID(doc, attr)— removes the attribute’s ID entry. Returns 0 on success, -1 otherwise. - remove_
ref ⚠ - Upstream
xmlRemoveRef(doc, attr)— removes the attribute’s IDREF entry. Returns 0 on success, -1 otherwise. - set_
valid_ ⚠errors - Set error and warning callbacks on a validation context.
- validate_
attribute_ ⚠decl - Validate an attribute’s value against its declaration.
- validate_
attribute_ ⚠value - Validate an attribute value against its declared type.
- validate_
build_ ⚠content_ model - Upstream
xmlValidBuildContentModel(ctxt, elem): compile the element’s content tree into a content-model NFA cached inelem->contModel. Returns 1 on success, 0 on failure. - validate_
content ⚠ - Validate the content of an element node against its content model.
- validate_
document ⚠ - Validate an entire document against its DTD.
- validate_
document_ ⚠final - Final validation: check that all IDREFs resolve to existing IDs.
- validate_
dtd ⚠ - Validate a DTD’s declarations (element/attribute declarations).
- validate_
dtd_ ⚠final - Final DTD validation — checks ID/IDREF consistency.
- validate_
element ⚠ - Validate a single element node against its DTD element and attribute declarations.
- validate_
element_ ⚠decl - Upstream
xmlValidateElementDecl(ctxt, doc, elem): verifies the declaration is not duplicated and that MIXED content models do not list the same element twice. - validate_
enumeration ⚠ - Validate that
valueis one of the values in the enumeration. - validate_
id ⚠ - Validate an ID value: check that the value is a valid XML Name and that no duplicate ID values exist in the document.
- validate_
id_ ⚠ref - Validate an IDREF value: check that the referenced ID exists in the document.
- validate_
id_ ⚠refs - Validate IDREFS (whitespace-separated list of IDREF values).
- validate_
name ⚠ - Validate whether
valueis a valid XML Name. - validate_
name_ ⚠space - Modern 2-arg form, upstream tree.c
xmlValidateName(value, space). - validate_
name_ ⚠value - Upstream
xmlValidateNameValue(value)— 1 if valid, 0 otherwise. - validate_
names ⚠ - Validate whether
valueis a whitespace-separated list of XML Names. - validate_
names_ ⚠value - Upstream
xmlValidateNamesValue(value)— 1 if valid, 0 otherwise. - validate_
ncname ⚠ - Modern 2-arg form, upstream tree.c
xmlValidateNCName(value, space). - validate_
nmtoken ⚠ - Validate whether
valueis a valid XML NMTOKEN. - validate_
nmtoken_ ⚠space - Modern 2-arg form, upstream tree.c
xmlValidateNMToken(value, space). - validate_
nmtoken_ ⚠value - Upstream
xmlValidateNmtokenValue(value)— 1 if valid, 0 otherwise. - validate_
nmtokens ⚠ - Validate whether
valueis a whitespace-separated list of XML NMTOKENs. - validate_
nmtokens_ ⚠value - Upstream
xmlValidateNmtokensValue(value)— 1 if valid, 0 otherwise. - validate_
notation_ ⚠decl - Upstream
xmlValidateNotationDecl(ctxt, doc, nota): modern libxml2 has no validity constraint on notation declarations and returns 1 always (verified by disassembly of the system DSO:mov $1,%eax; ret). - validate_
notation_ ⚠use - Validate that
notationNameis a declared notation in the document’s DTD. - validate_
one_ ⚠attribute - Upstream
xmlValidateOneAttribute(ctxt, doc, elem, attr, value). - validate_
one_ ⚠element - Upstream
xmlValidateOneElement(ctxt, doc, elem)— validates a single element against its declaration (content model + attributes), WITHOUT recursing into children. - validate_
one_ ⚠namespace - Upstream
xmlValidateOneNamespace(ctxt, doc, elem, prefix, ns, value)— namespace-declaration attribute validation. - validate_
pop_ ⚠element - Upstream
xmlValidatePopElement(ctxt, doc, elem, qname): verify the parent content model completed and pop the validation state. - validate_
push_ ⚠cdata - Upstream
xmlValidatePushCData(ctxt, data, len): character data is only legal as whitespace inside ELEMENT content. - validate_
push_ ⚠element - Upstream
xmlValidatePushElement(ctxt, doc, elem, qname): validate a start tag against the parent’s content model and push the new element’s validation state. - validate_
qname ⚠ - Modern 2-arg form, upstream tree.c
xmlValidateQName(value, space). - validate_
root ⚠ - Validate the root element of a document.