diff --git a/CHANGELOG.md b/CHANGELOG.md
index 76df29b..ee4299f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -21,6 +21,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
+- XSTS invalid-schemas-accepted (#145): a `complexType` nested in an `element` is a local, anonymous type and may not carry a `name` attribute; only a top-level `complexType` (or a `redefine` redefinition) is named. invalid-schemas-accepted 81 → 80, no false positive (valid-schemas-rejected held at 0), no other bucket moved.
+
- XSTS invalid-schemas-accepted (#161): a type inside `xs:redefine` must restrict or extend the type it redefines, which lives in the redefining schema's own target namespace (`src-redefine.5`). A derivation base bound to a different namespace, such as an imported type that happens to share the redefined type's local name, is not a self-redefinition and is now rejected; the previous check compared local names only and accepted it. A base with no resolvable namespace is left alone, so an unprefixed or own-namespace self-reference is unaffected. invalid-schemas-accepted 84 → 81, no false positive (valid-schemas-rejected held at 0; differential PureXML-stricter unchanged at 87 over 9618 schemas), no other bucket moved.
- XSTS invalid-schemas-accepted (#161): an `import`'s `namespace` attribute must equal the `targetNamespace` of the schema document it resolves to (`src-import.3.1`/`3.2`): both present and equal, or both absent. Importing a no-namespace document under a declared namespace, or a document whose target namespace differs from the declared one, is now rejected. Checked only when the `schemaLocation` resolves to a loaded schema (an unresolved import is the processor's choice and not an error); imports keep their own target namespace, so no chameleon adjustment applies. invalid-schemas-accepted 87 → 84, no false positive (valid-schemas-rejected held at 0; differential PureXML-stricter unchanged at 87 over 9618 schemas), no other bucket moved.
diff --git a/Sources/Schema/SchemaStructure.swift b/Sources/Schema/SchemaStructure.swift
index 5983ee6..0d45538 100644
--- a/Sources/Schema/SchemaStructure.swift
+++ b/Sources/Schema/SchemaStructure.swift
@@ -130,6 +130,7 @@ extension PureXML.Schema.XSDParser {
case "complexType":
errors += elementDeclsConsistentErrors(node)
errors += complexTypeOrderErrors(node)
+ errors += localComplexTypeNameErrors(node)
case "complexContent":
errors += complexContentOrderErrors(node)
case "simpleContent":
diff --git a/Sources/Schema/SchemaStructureHelpers.swift b/Sources/Schema/SchemaStructureHelpers.swift
index eb0d228..28fa3a4 100644
--- a/Sources/Schema/SchemaStructureHelpers.swift
+++ b/Sources/Schema/SchemaStructureHelpers.swift
@@ -227,6 +227,18 @@ extension PureXML.Schema.XSDParser {
return errors
}
+ /// A `complexType` nested in an `element` is a local (anonymous) type and must
+ /// not carry a `name`; only a top-level `complexType` (a child of `schema`, or a
+ /// `redefine` redefinition) is named. A local type definition has no name.
+ static func localComplexTypeNameErrors(_ node: XSDTree) -> [String] {
+ guard PureXML.Schema.XSDNode.attribute(node, "name") != nil,
+ let parent = node.parent,
+ parent.name?.namespaceURI == xsdNamespace,
+ PureXML.Schema.XSDNode.localName(parent) == "element"
+ else { return [] }
+ return ["a complexType nested in an element must not have a 'name' attribute"]
+ }
+
/// The content model of an identity constraint (`unique`/`key`/`keyref`) is
/// `(annotation?, selector, field+)`: exactly one `selector`, then one or more
/// `field`s, in that order. A `field` before the `selector`, a second
diff --git a/Tests/SchemaStructureTests.swift b/Tests/SchemaStructureTests.swift
index 7458729..cad3088 100644
--- a/Tests/SchemaStructureTests.swift
+++ b/Tests/SchemaStructureTests.swift
@@ -371,4 +371,24 @@ struct SchemaStructureOrderTests {
"""#))
}
+
+ /// A complexType nested in an element is a local (anonymous) type and must not
+ /// carry a name; only a top-level complexType is named.
+ @Test("a local complexType may not have a name")
+ func test_localComplexTypeMustBeAnonymous() {
+ #expect(rejects(#"""
+
+
+
+
+
+ """#))
+ // A top-level named complexType, and an anonymous local one, are both valid.
+ try? compile(#""#)
+ #expect(!rejects(#"""
+
+
+
+ """#))
+ }
}
diff --git a/Tests/XSTSSuiteTests.swift b/Tests/XSTSSuiteTests.swift
index 65e9e79..6d5f451 100644
--- a/Tests/XSTSSuiteTests.swift
+++ b/Tests/XSTSSuiteTests.swift
@@ -151,9 +151,10 @@ struct XSTSSuiteTests {
/// an import's namespace must equal the imported targetNamespace (src-import.3)
/// 87->84; and a redefined type must derive from the type it redefines in the
/// redefining schema's own namespace, not a same-named foreign one (src-redefine.5)
- /// 84->81.
+ /// 84->81; and a complexType nested in an element must be anonymous (no name)
+ /// 81->80.
private let knownSchemaValidRejected = 0
- private let knownSchemaInvalidAccepted = 81
+ private let knownSchemaInvalidAccepted = 80
private let knownInstanceValidRejected = 0
private let knownInstanceInvalidAccepted = 133