Root Swift package mirroring PureYAML's structure, rules, and verification gates. Includes the XML node model (Node, Element, Attribute, QualifiedName), a working emitter (Serializer) with escaping and pretty/compact options, and structural validation. The parser surface is stable; parse() raises notImplemented until the scanner lands, pinned by a test. - dependency-free, namespaced under PureXML - portability and style gates carried over (style, namespacing, forbidden patterns, swiftformat, swiftlint, linux, wasm, windows CI) - 11 tests passing
26 lines
1.1 KiB
Swift
26 lines
1.1 KiB
Swift
public extension PureXML.Model {
|
|
/// A node in an XML tree. The model preserves document order and the
|
|
/// distinction between text, CDATA, comments, and processing instructions
|
|
/// so that emitting can round-trip a parsed document.
|
|
indirect enum Node: Equatable, Hashable, Sendable {
|
|
/// The root of a parsed document, holding its prolog and root element.
|
|
case document([Node])
|
|
/// An element with a name, attributes, and children.
|
|
case element(Element)
|
|
/// Character data between markup.
|
|
case text(String)
|
|
/// A `<![CDATA[ ... ]]>` section. Stored as its raw inner text.
|
|
case cdata(String)
|
|
/// A `<!-- ... -->` comment. Stored as its raw inner text.
|
|
case comment(String)
|
|
/// A `<?target data?>` processing instruction.
|
|
case processingInstruction(target: String, data: String)
|
|
|
|
/// The wrapped ``Element`` when this node is an element.
|
|
public var element: Element? {
|
|
guard case let .element(element) = self else { return nil }
|
|
return element
|
|
}
|
|
}
|
|
}
|