Re: Identity Constraints

From: "Robyn Dean" <rdean@fourbit.com> wrote:

> I would like the instance document to look like:
> <FruitSalad>
> <apple ref="Granny"/>
> <apple canEatSkin="true" color="yellow" makesGoodPie="false"/>
> <banana canEatSkin="false"/>
> </FruitSalad>
> <apple name="Granny" color="green" canEatSkin="true" makesGoodPie="true"/>
> <apple name="SnowWhite's" color="red" canEatSkin="false"
> makesGoodPie="false"/>

Well, that wouldn't be a valid XML document since there are multiple top
level elements.  You can used xs:key and xs:keyref to perform that type of
validation, however they are defined on the containing element.  If you
wrapped everything in a <RecipeBook> element and then added something like:

<xs:element name="RecipeBook">
...
<xs:key name="appleNames">
  <xs:selector xpath="apple"/>
  <xs:field xpath="@name"/>
</xs:key>
<xs:keyref name="appleRefs" refer="appleNames">
  <xs:selector xpath="//apple[@ref]"/>
  <xs:field xpath="@ref"/>
</xs:keyref>

Look at the primer for more examples.  Not sure if the [@ref] is legal or
necessary.  Should give you enough to review the docs.

Received on Tuesday, 23 October 2001 04:10:06 UTC