PureXML/Sources/Model/Element.swift
Mihaela Mihaljevic 708390242c chore: scaffold PureXML pure-Swift XML package
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
2026-06-07 23:20:20 +02:00

43 lines
1.2 KiB
Swift

public extension PureXML.Model {
/// An XML element: a qualified name, ordered attributes, and ordered child nodes.
struct Element: Equatable, Hashable, Sendable {
public var name: QualifiedName
public var attributes: [Attribute]
public var children: [Node]
public init(
name: QualifiedName,
attributes: [Attribute] = [],
children: [Node] = [],
) {
self.name = name
self.attributes = attributes
self.children = children
}
public init(
_ name: String,
attributes: [Attribute] = [],
children: [Node] = [],
) {
self.init(
name: QualifiedName(name),
attributes: attributes,
children: children,
)
}
/// The concatenated text of direct text and CDATA children.
public var text: String {
children.reduce(into: "") { accumulated, child in
switch child {
case let .text(value), let .cdata(value):
accumulated += value
default:
break
}
}
}
}
}