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
29 lines
1007 B
Swift
29 lines
1007 B
Swift
public extension PureXML {
|
|
/// Parses an XML document into a ``Model/Node`` tree.
|
|
///
|
|
/// The parser is still being built; this entry point currently raises
|
|
/// ``Parsing/ParseError/notImplemented(_:)``. The serializer and model are
|
|
/// usable today for building and emitting trees.
|
|
static func parse(_ xml: String) throws -> Model.Node {
|
|
try Parsing.Parser().parse(xml)
|
|
}
|
|
|
|
/// Serializes a ``Model/Node`` tree into XML with the selected options.
|
|
static func serialize(
|
|
_ node: Model.Node,
|
|
options: Emitting.Options = .default,
|
|
) -> String {
|
|
Emitting.Serializer(options: options).serialize(node)
|
|
}
|
|
|
|
/// Validates a parsed XML node with the default validation rules.
|
|
@discardableResult
|
|
static func validate(
|
|
_ node: Model.Node,
|
|
using validator: Validation.Validator = .init(),
|
|
strict: Bool = true,
|
|
) throws -> [Validation.Issue] {
|
|
try validator.validate(node, strict: strict)
|
|
}
|
|
}
|