Surface the parsed <!DOCTYPE> internal subset's <!ELEMENT> declarations from the parser and validate a tree against them. Reimplemented from the DTD content-model spec; no upstream code copied. - DoctypeScanner captures <!ELEMENT name model> declarations; the parser surfaces them as Parsing.DocumentType (via parseWithDocumentType). - Validation.ContentModel + ContentModelParser parse a model string (EMPTY, ANY, (#PCDATA), mixed, and element content with sequence/choice and ?/*/+). - ContentModelMatcher matches the child element-name sequence against a model as a regular language (NFA-position matching). - Validation.DTDSchema.validate reports issues for EMPTY/PCDATA/mixed violations, element content with stray text, and child sequences that do not match. - PureXML.validateAgainstInternalDTD(_:) parses and validates in one call. - ATTLIST validation is out of scope. 9 tests; 70 total.
16 lines
594 B
Swift
16 lines
594 B
Swift
extension PureXML.Validation {
|
|
/// A DTD element content model, as declared by `<!ELEMENT name ...>`.
|
|
enum ContentModel: Equatable {
|
|
/// `EMPTY`: the element must have no content.
|
|
case empty
|
|
/// `ANY`: any content is allowed.
|
|
case any
|
|
/// `(#PCDATA)`: character data only, no child elements.
|
|
case pcdata
|
|
/// `(#PCDATA | a | b)*`: text mixed with zero or more of the named elements.
|
|
case mixed([String])
|
|
/// Element content: a particle the child element sequence must match.
|
|
case children(Particle)
|
|
}
|
|
}
|