Add the PureXML.XInclude namespace: RFC 3986 reference resolution (URIReference with dot-segment removal) and an xi:include processor over the value tree. href resolves against the base and in-scope xml:base; parse=xml includes the document element or an xpointer() fragment (via PureXML.XPointer), parse=text includes raw text, and a failed load uses xi:fallback or errors. Includes nest. No I/O is done internally: fetching is only through the injected loadingURI closure, so the default fetches nothing. Closes #48 Closes #49 Closes #50 Closes #51 Closes #24
20 lines
817 B
Swift
20 lines
817 B
Swift
public extension PureXML.XInclude {
|
|
/// An error during XInclude processing.
|
|
enum XIncludeError: Swift.Error, Equatable, Sendable, CustomStringConvertible {
|
|
/// An `xi:include` had no `href` and no usable fallback.
|
|
case missingHref
|
|
/// The resource could not be loaded and there was no `xi:fallback`.
|
|
case unresolved(String)
|
|
/// Includes nested past the recursion limit (a likely include loop).
|
|
case toodeep
|
|
|
|
public var description: String {
|
|
switch self {
|
|
case .missingHref: "an xi:include has no href and no fallback"
|
|
case let .unresolved(href): "could not resolve xi:include href '\(href)' and no fallback"
|
|
case .toodeep: "xi:include nesting is too deep (possible loop)"
|
|
}
|
|
}
|
|
}
|
|
}
|