XSD Key/KeyRef and how to reference

483 Views Asked by At

We use XML to define a model which we later use to generate code. The file looks something like this:

<def xmlns="http://tempuri.org/schema.xsd" xmlns:xsi="http://tempuri.org/schema.xsd">
  <ns xmlns=""  name="asd">
    <alias name="NicknameType" ref="String" />
    <alias name="SomethingType" ref="o3" />

    <obj1 name="o1">
       <element name="Nick" ref="NicknameType" />
    </obj1 >

    <obj2 name="o2">
        <action name="a1">
            <attribute name="TheObject1" ref="o1" />
        </action>
    </obj2 >

    <obj3 name="o3">
        <element name="SomeText" ref="int32" />
    </obj3 >
  </ns>
</def>

What I would really like to enforce is that the ref-attribute of any tag matches the name tag of either an alias-tag, an obj1-tag or an obj2 tag or some predefined values such as String or int32. I already defined the general structure that the file has to have in XSD. Is what I would like to achieve even possible with XSD?

Thanks

1

There are 1 best solutions below

0
Michael Kay On BEST ANSWER

It's possible in XSD 1.1, using assertions, but not in XSD 1.0.

The latest releases of the schema processors in Saxon and Xerces both have support for assertions.