Read and enforce the XSD 1.0 derivation controls that were previously ignored: - abstract elements may not appear in an instance directly, only through a substitution member; an element of an abstract complex type must supply an xsi:type naming a concrete derived type. - block on a type forbids the disallowed xsi:type substitutions; block on an element drops substitution-group members that derive by a blocked method. - final on a type rejects, at compile time, any type that derives from it by a final method. - xs:redefine requires the redefined type to derive from itself. Track each named complex type's base and derivation method as the backbone these checks walk. Also compose complexContent extension and restriction content models, which were previously dropped: an extension now inherits its base's attributes and content (base first, then the extension, in sequence). Complex-type restriction is not verified to be a structurally valid subset of its base (Particle Valid (Restriction)); that limit is documented at its sites. Closes #76
34 lines
1.6 KiB
Swift
34 lines
1.6 KiB
Swift
extension PureXML.Schema.XSDParser {
|
|
/// The `xs:anyAttribute` wildcard declared directly under `node`, if any.
|
|
static func attributeWildcard(under node: XSDTree, _ context: PureXML.Schema.XSDContext) -> PureXML.Schema.Wildcard? {
|
|
PureXML.Schema.XSDNode.firstChild(node, named: "anyAttribute").map { wildcard($0, context) }
|
|
}
|
|
|
|
/// Parses a wildcard's `namespace` and `processContents` constraints.
|
|
static func wildcard(_ node: XSDTree, _ context: PureXML.Schema.XSDContext) -> PureXML.Schema.Wildcard {
|
|
let processContents: PureXML.Schema.ProcessContents = switch PureXML.Schema.XSDNode.attribute(node, "processContents") {
|
|
case "skip": .skip
|
|
case "lax": .lax
|
|
default: .strict
|
|
}
|
|
let namespace = wildcardNamespace(PureXML.Schema.XSDNode.attribute(node, "namespace"), context)
|
|
return PureXML.Schema.Wildcard(namespace: namespace, processContents: processContents, targetNamespace: context.targetNamespace)
|
|
}
|
|
|
|
private static func wildcardNamespace(_ value: String?, _ context: PureXML.Schema.XSDContext) -> PureXML.Schema.WildcardNamespace {
|
|
switch value {
|
|
case nil, "##any": return .any
|
|
case "##other": return .other
|
|
default:
|
|
let uris = (value ?? "").split(whereSeparator: \.isWhitespace).map { token -> String in
|
|
switch token {
|
|
case "##targetNamespace": context.targetNamespace ?? ""
|
|
case "##local": ""
|
|
default: String(token)
|
|
}
|
|
}
|
|
return .enumerated(Set(uris))
|
|
}
|
|
}
|
|
}
|