XSD validating value of child reference element
I need to create an XSD that validates the value in a specific compl开发者_高级运维ex type from a different namespace with specific enumerations.
In this specific case the XML will look like this:
<Format>
<name>
<gco:CharacterString>IMG</gco:CharacterString>
</name>
<version>
<gco:CharacterString>Version 1.0</gco:CharacterString>
</version>
</Format>
It is a requiremement that all values validate as gco:CharacterString referenced from a seperate namespace (this is really a simple xs:string type in the other namespace, but I need to reference it).
I need name and version to validate for specific enumerations of values inside their gco:CharacterString child node. In this case I want to validate that the following enumerations exist and are valid for gco:Characterstring:
name: IMG GEO NIT
version: version 1.0 version 2.0 version 3.0
Adding the enumerations to the referenced gco:Characterstring isn't an option, because I need these to be specific for both version and name. Is this possible to set this up in the XSD?
Not in XML Schema 1.0.
With XML Schema 1.1 - something like:
<assert test="(name/gco:CharacterString eq 'IMG)
and (version/gco:CharacterString eq 'Version 1.0')"/>
It's not possible in XSD 1.0. There's a built-in assumption in XSD that the rules for validating elements in a namespace are context-free: that is, if one namespace imports another, the rules for elements in the second namespace won't depend on where the elements occur. I would suggest you're not using namespaces "properly".
精彩评论