XSD (XML Schema) Hierarchical Unique Contraint
While working on RegexConverter I've started learning things about XML. I disliked it before, but now... I loathe it completely. It feels like the XML people are from another planet and I have to twist my brain at straight angles just to understand what they meant.
One of the problems I met was "how to declare in an XML schema a unique constraint/index on the entire document when there are nested elements of the same type". In other words, something like this:
Bottom line:
Concrete example:
I tried to solve this for two hours only to find the solution was this idiotic. Neither one of "group","mstns:group","mstns:group|.//group" work. The only one is "mstns:group|.//mstns:group".
Grrrr...
One of the problems I met was "how to declare in an XML schema a unique constraint/index on the entire document when there are nested elements of the same type". In other words, something like this:
<regex>
<group index="1">
<group index="2">
</group>
<group index="3">
</group>
</group>
Bottom line:
- Use the declared namespace
- Declare the index in the root element
- Use the name of the nested element (in my case group) in the selector
- Use the one or more levels deep selector (.//)
- Use the declared namespace AGAIN.
Concrete example:
<xs:element name="regex" type="regexType">
<xs:unique name="uniqueIndex">
<xs:selector xpath="mstns:group|.//mstns:group"></xs:selector>
<xs:field xpath="@index"></xs:field>
</xs:unique>
</xs:element>
I tried to solve this for two hours only to find the solution was this idiotic. Neither one of "group","mstns:group","mstns:group|.//group" work. The only one is "mstns:group|.//mstns:group".
Grrrr...
Comments
Be the first to post a comment