Expand description
DTD validation walk.
Given a Document and its captured Dtd, check every element
and attribute against the declarations. Returns the first error
encountered (libxml2 stops at first fatal error in
xmlValidateDocument too).
§Algorithm
Two passes:
- Tree walk — for each element node:
- Look up its
<!ELEMENT>decl. If absent in a non-empty DTD, that’s an error (libxml2’s “No declaration for element foo”). - Match its child sequence against the content model.
- Check each attribute against the corresponding
<!ATTLIST>: required ones present, enumerated values valid, FIXED values equal, IDs unique, IDREFs recorded for pass 2.
- Look up its
- Cross-ref pass — every IDREF target collected in pass 1 must equal some ID seen anywhere in pass 1.
The content-model matcher is a small recursive descent over the
Group tree. We don’t bother with NFA→DFA conversion: real
DTD content models are tiny (rarely more than a few dozen
particles), and recursive matching with greedy/lazy fallback on
?/*/+ handles them in microseconds.
Structs§
- DtdError
- One DTD validation failure. Mirrors libxml2’s per-error structure shape just enough for the compat layer to surface.