PureXML/Sources/XInclude/XIncludeRequest.swift
Mihaela Mihaljevic b13cdca739 feat(xinclude): content-negotiation hints, cycle detection, text+fragment
Three XInclude gaps from the audit:

- accept / accept-language / encoding are surfaced to the loader via a new
  XIncludeRequest and a process(_:base:loading:) overload, so a loader can
  honor content negotiation. The existing loadingURI form is kept.
- Cycle detection tracks the visited (resolved-URI) set along the current
  inclusion chain and raises XIncludeError.cycle, instead of relying only
  on the depth backstop; a non-cyclic diamond include is not flagged.
- parse="text" combined with an xpointer is rejected
  (XIncludeError.textWithFragment), since a fragment cannot select within
  unparsed text.

xpointer range() inclusion still depends on the XPointer range() scheme
(tracked in the XPointer issue).

Part of #87
2026-06-08 15:52:18 +02:00

33 lines
1.3 KiB
Swift

public extension PureXML.XInclude {
/// A request to load one `xi:include` target, carrying the resolved URI and the
/// include's content-negotiation hints, so a loader can honor them. PureXML
/// performs no I/O itself; the loader decides what (if anything) to fetch.
struct XIncludeRequest: Equatable, Sendable {
/// The resolved absolute (or base-relative) URI to load.
public let uri: String
/// The `accept` attribute, an HTTP Accept hint, or nil.
public let accept: String?
/// The `accept-language` attribute, an HTTP Accept-Language hint, or nil.
public let acceptLanguage: String?
/// The `encoding` attribute for a `parse="text"` inclusion, so the loader
/// can decode the bytes; nil for a parsed (XML) inclusion.
public let encoding: String?
/// Whether the inclusion is unparsed text (`parse="text"`) rather than XML.
public let isText: Bool
public init(
uri: String,
accept: String? = nil,
acceptLanguage: String? = nil,
encoding: String? = nil,
isText: Bool = false,
) {
self.uri = uri
self.accept = accept
self.acceptLanguage = acceptLanguage
self.encoding = encoding
self.isText = isText
}
}
}