From 963c7c74ebda63c906a921034dc0ea9f95e95b57 Mon Sep 17 00:00:00 2001 From: Mihaela Mihaljevic Date: Tue, 9 Jun 2026 18:58:27 +0200 Subject: [PATCH] fix(xsd): locate identity-constraint errors at the offending field Extend an identity error's coding path past the target element to the single field the constraint names: an attribute (list/item[2]/@id) or a child element (.../code), resolved from the field XPath. Multi-field or complex-path constraints stay on the target. Also add a cross-scope keyref test confirming a keyref resolves against a key declared on an ancestor element. Updates the identity-path tests to the more precise locations. Closes #104 --- CHANGELOG.md | 1 + README.md | 4 +- Sources/Schema/IdentityValidator.swift | 26 ++++++++-- Tests/XSDIdentityTests.swift | 66 ++++++++++++++++++++++---- 4 files changed, 83 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fa0a9f7..f16ab71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- XSD identity-constraint errors now locate the offending field, not just the element (#104): a single-field `key`/`keyref`/`unique` error extends the coding path with the field itself, an attribute (`... at path: list/item[2]/@id`) or a child element (`.../code`), resolved from the constraint's field XPath. keyref scope resolution is confirmed to resolve a key declared on an ancestor element (cross-scope), with a test. Full XSD qualified-node-set conformance for pathological multi-level same-name nesting remains part of the conformance-corpus work. - XSD identity-constraint errors (`key`, `keyref`, `unique`) now carry a coding path locating the actual offending element, instead of always rendering "at root of document". The `IdentityValidator` walk threads a `[PathKey]` the same way the content-model validator does, and each error is located at the selected target node, so a duplicate-key failure reports "... at path: list/item[2]" and a dangling keyref "... at path: orders/line" rather than an empty path. This brings the identity-constraint rule into line with the validation framework's path-carrying contract, which every other rule already honored. The "no element declaration for the root" XSD error is likewise located at the root element, matching the namespace check beside it. - A `