PureXML/Sources/Parsing/ParsedDocument.swift
Mihaela Mihaljevic 9168f990d6 feat(parsing): surface the XML declaration (version, encoding, standalone)
Parse the XML declaration's pseudo-attributes instead of skipping the
<?xml?> processing instruction:

- version, encoding, and standalone are surfaced on a new XMLDeclaration,
  returned from parseWithDocumentType and via PureXML.xmlDeclaration(_:).
- The pseudo-attributes are validated: fixed order (version, encoding,
  standalone), known names only, and standalone must be yes or no. A
  malformed declaration is rejected.
- The declared version is now readable, a prerequisite for XML 1.1.

parseWithDocumentType returns a ParsedDocument struct (node,
documentType, declaration) rather than a 2-tuple; the member names are
unchanged so existing call sites are unaffected.

Closes #95
2026-06-08 14:53:04 +02:00

17 lines
680 B
Swift

public extension PureXML.Parsing {
/// A parsed document together with the metadata gathered alongside its tree:
/// the parsed DTD (entities, content models, notations, and so on) and the XML
/// declaration, when the document opens with one.
struct ParsedDocument: Sendable {
public var node: PureXML.Model.Node
public var documentType: DocumentType
public var declaration: XMLDeclaration?
public init(node: PureXML.Model.Node, documentType: DocumentType, declaration: XMLDeclaration? = nil) {
self.node = node
self.documentType = documentType
self.declaration = declaration
}
}
}