Rebuild the XPath engine on the parent-aware tree. Add an XPath node abstraction (tree, attribute, namespace) with document order, and navigate all thirteen axes: child, descendant, parent, ancestor, following-sibling, preceding-sibling, following, preceding, attribute, namespace, self, descendant-or-self, ancestor-or-self. Support the ./../@/// abbreviations and processing-instruction() node tests. Reverse axes number nearest-first for positional predicates; results return de-duplicated in document order. The attribute axis excludes xmlns declarations; the namespace axis surfaces in-scope namespace nodes. Closes #40
24 lines
978 B
Swift
24 lines
978 B
Swift
public extension PureXML.XPath {
|
|
/// An error compiling or evaluating an XPath query in the supported subset.
|
|
enum QueryError: Swift.Error, Equatable, Sendable, CustomStringConvertible {
|
|
case empty
|
|
case unexpectedToken(String)
|
|
case expectedNodeTest
|
|
case unterminatedPredicate
|
|
case unsupportedPredicate(String)
|
|
/// An axis name was not one of the thirteen XPath axes.
|
|
case unsupportedAxis(String)
|
|
|
|
public var description: String {
|
|
switch self {
|
|
case .empty: "the XPath expression is empty"
|
|
case let .unexpectedToken(token): "unexpected token '\(token)'"
|
|
case .expectedNodeTest: "expected a node test"
|
|
case .unterminatedPredicate: "unterminated predicate"
|
|
case let .unsupportedPredicate(detail): "unsupported predicate: \(detail)"
|
|
case let .unsupportedAxis(axis): "unsupported axis: \(axis)"
|
|
}
|
|
}
|
|
}
|
|
}
|