Search code examples
xmlvalidationxsdkeykeyref

XML key/keyref across multiple XML instances


is it possible to validate key/keyref across multiple XML instances. Example: xsd1 defines a schema and namespace for a list of DataTypes, each DataType has a unique identifier ID which is defined as a keyref. xsd2 defines a list of entities, that shall use the IDs from xsd1. In the XML authoring software Oxygen e.g. the xsd-referencing with key/keyref across the two namespaces works, but I do not manage to create a validation scenario like: "Field X in XML2 (validated against xsd2) can only contain values from the fields ID in XML1(validated against xsd1)"

Is this possible in XML-authoring state at all? Or would I always have to implement that validation manually? Which wouldn't be a big deal, but it might be helpful to provide users with a sophisticated authoring-validation-toolbox if such exists.

Many thanks in advance!


Solution

  • It is not possible to do it with XSD. You could do it across documents using Schematron. Now, Schematron equivalent for key/keyref is not that declarative as its XSD counterpart, but nonetheless doable. Have a look at this article for details... keep in mind that it is meant to be a generic solution to the key/unique/keyref construct, you could probably do it simpler for your particular case.