Skip to main content

Module dtd

Module dtd 

Source
Expand description

DTD validation engine.

Captures <!ELEMENT> and <!ATTLIST> declarations during parse, then validates a parsed Document against them.

§Scope

Covers the subset of XML 1.0 § 3.2–3.3.4 that real consumers actually rely on:

  • Element content models: EMPTY, ANY, Mixed ((#PCDATA | a | b)*), and children models ((a, b), (a | b)+, etc.) with the standard occurrence indicators (?, *, +, none).
  • Attribute declarations: every type from § 3.3.1 (CDATA, ID, IDREF, IDREFS, ENTITY, ENTITIES, NMTOKEN, NMTOKENS, NOTATION, enumerated), with all four DefaultDecl flavours (#REQUIRED, #IMPLIED, #FIXED "...", literal default).
  • ID uniqueness across the whole document.
  • IDREF / IDREFS targets must resolve to an attribute typed ID.

§Not yet covered

  • Default attribute injection on parse (when an ATTLIST default would supply a missing attribute, our parser ignores it).
  • Notation cross-references (NOTATION decls are stored but the set of declared notations is not consulted).
  • Parameter-entity-driven declarations inside the external subset.
  • Conditional sections (<![INCLUDE[ ... ]]>).

Re-exports§

pub use inject::inject_defaults;
pub use inject::inject_defaults_from;
pub use model::AttDecl;
pub use model::AttDefault;
pub use model::AttType;
pub use model::ContentModel;
pub use model::DeclRef;
pub use model::ElementDecl;
pub use model::EntityDecl;
pub use model::Group;
pub use model::GroupKind;
pub use model::Item;
pub use model::Occurrence;
pub use model::Particle;
pub use validate::validate;
pub use validate::DtdError;

Modules§

inject
Default attribute injection per XML 1.0 § 3.3.2.
model
Type-level DTD vocabulary — Element/Attribute decls and content models.
validate
DTD validation walk.

Structs§

Dtd
Parsed DTD content used by [validate]. Built up incrementally by the bytes-reader as it encounters <!ELEMENT> / <!ATTLIST> declarations in the internal subset.

Functions§

collect_id_attrs
Map element local-name → set of ATTLIST-declared ID-type attribute names on that element. Used by id() (XPath 1.0 §4.1) to walk only the DTD-typed attributes; without this map every attribute literally named id is treated as an ID, which catches some real-world cases but misses DTDs that declare an ID attribute under a different name.
collect_idref_attrs
Map element local-name → set of ATTLIST-declared IDREF / IDREFS attribute names on that element. Used by idref() (XPath 2.0 §14.5.5) to locate the attributes that reference a candidate ID.