다음을 통해 공유


XML Schema Constraints

It's been a while since I looked at the XML Schema spec but some work I was doing last week caused me to go brush up on it. While going over it I was reminded of how bad my last encounter with it went. It turns out that if you read the XML Schema spec you should also read the errata. There are some significant changes to the XML Schema Primer in there.

It also occurs to me that I still don't know how to solve the problem I was facing. Given the following tree.

 

I want to write an XML Schema with key constraints on A elements (scoped to the containing root element). I also want some constraints on A Child scoped ot the A element they fall in. Those are easy to do. Now I want to use KeyRefs in B to first ensure that each A Ref refers to a valid A and then to ensure that  each A Child Ref refers to a valid A Child in the A that the parent A Ref refers to. To the best of my knowledge this is impossible in XML Schema 1.0 Does anyone have a workaround they know of?

Comments

  • Anonymous
    March 11, 2004
    You could do an XPath assertion on insert of the A Child Ref node to verify that A Child exists. It's not the best option, but it'd probably work.