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.
15 lines
571 B
Swift
15 lines
571 B
Swift
public extension PureXML.Parsing {
|
|
/// What the parser extracted from a `<!DOCTYPE>` internal subset: the
|
|
/// internal general entities and the `<!ELEMENT>` content-model strings.
|
|
/// Empty when no DTD was processed.
|
|
struct DocumentType: Equatable, Sendable {
|
|
public var entities: [String: String]
|
|
public var elementModels: [String: String]
|
|
|
|
public init(entities: [String: String] = [:], elementModels: [String: String] = [:]) {
|
|
self.entities = entities
|
|
self.elementModels = elementModels
|
|
}
|
|
}
|
|
}
|