Reputation: 1113
I have my xml document containing several elements which have an attribute xml:lang.
I want to restrict the values which are allowable for the attribute's value; i.e. only allow "en-US, en-CA".
I've tried adding a restriction, but since the value is referenced that doesn't seem to be valid:
<xs:element name="translation">
<xs:complexType>
<xs:sequence>
<xs:element ref="name" />
</xs:sequence>
<xs:attribute ref="xml:lang" use="required"/>
</xs:complexType>
</xs:element>
Getting the namespace to import was difficult enough and I can't seem to find any good resources on adding restrictions/enumerations to it =(
Upvotes: 1
Views: 332
Reputation: 21658
Unfortunately, there is no easy way to achieve it. The options you have are definitely not that used.
A quick (and dirty) way is to copy the original xml.xsd on your local machine; edit the xml.xsd file to have the definition you want for the xml:lang attribute; and through some generic mechanism (e.g. catalogs if you want to use dangling types), or simply xsd:import to your modified file, instruct your stack/tooling to use the amended definition. It might not even work in some cases, since some tools may be stubborn enough to use an internal, cached copy, of the xml.xsd; can't comment, since you have not indicated the stack you're on.
There is no clean way to do it in XSD 1.0, simply because xsd:redefine only works for types, and groups of particles and attributes. Since xml:lang is of xsd:language type, there is no way to redefine that to constrain it only to the enumerations you want.
xsd:override in XSD 1.1 would allow for unconstrained replacement; unfortunately, I would be surprised to see a mainstream implementation of the new XSD version.
Upvotes: 1