- From: Jeni Tennison <jeni@jenitennison.com>
- Date: Wed, 19 Jun 2002 10:49:13 +0100
- To: Jos van den Oever <oever@fenk.wau.nl>
- CC: xmlschema-dev@w3.org
Hi Jos, > I think I see now. So each object can have only one key of a certain > kind. But a list of keys can contain different types of objects. I think you're using 'key' in a different way from the way I do, but yes. Within each identity constraint, each element has a key value associated with it. That key value comes from combining the fields defined in the identity constraint, and for each element in the instance document, each field must only pick one element or attribute. > So this is valid: > >> <xs:key name="people"> >> <xs:selector xpath="person1 | person1/person2 | >> person1/person2/person3" /> >> <xs:field xpath="@name" /> >> </xs:key> > > But this isn't: > <xs:key name='acquaintances'> > <xs:selector xpath='acquaintance' /> > <xs:field xpath='@person1|@person2' /> > </xs:key> That *could* be valid -- it depends on the source XML. If you had XML like: <acquaintance person1="John" /> <acquaintance person2="Fred" /> i.e. where each acquaintance element could only have one of either person1 or person2 attributes, then the identity constraint is fine. On the other hand, if you had an acquaintance element like: <acquaintance person1="John" person2="Fred" /> then that wouldn't be valid, because the field's XPath would select two nodes. (This shows how you can use identity constraints to test some co-occurrence constraints in XML Schema, BTW.) Note that the acquaintance with both person1 and person2 attributes is valid with: <xs:key name="acquaintances"> <xs:selector xpath="acquaintance" /> <xs:field xpath="@person1" /> <xs:field xpath="@person2" /> </xs:key> but the acquaintance elements with only one and not the other are not valid. You could make them valid as well if you use xs:unique rather than xs:key in the above (xs:key means that the field *must* select one node, whereas xs:unique means that the field might not find a node). > I'm using xerces to validate xml files. However, xerces does not > seem to agree with these rules. It validates this: > > <person1 name='Pete'> > <person2 name='Pete'/> > </person1> What does the identity constraint look like? > and also, it does not give an error message if I use a scheme file > with a field like this: > <xs:field xpath='@person1|@person2' /> Having this in a schema isn't an error with the schema (XPaths are too complicated to validate, so the only kinds of errors in them that are detectable are those that occur in the XPath syntax, like trying to use a predicate for example). It should be an error if you have a selected element in the instance document that has both a person1 and a person2 attribute. Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/
Received on Wednesday, 19 June 2002 05:49:15 UTC