![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Here is some highly imaginative XML I've constructed to highlight what it is I'm trying to achieve. (Seems easier with an example). foobars <foo <bar x="dog" colour="brown"/ <bar x="cat" colour="grey"/ <bar x="fish" colour="gold"/ </foo <foo <bar x="dog" colour="black"/ <bar x="cat" colour="white"/ <bar x="fish" colour="blue"/ </foo /foobars I want to ENFORCE that every <foo> contains three <bar> children and that "dog", "cat", and "fish" appear each once. |
#3
| |||
| |||
|
|
Here is some highly imaginative XML I've constructed to highlight what it is I'm trying to achieve. (Seems easier with an example). foobars foo bar x="dog" colour="brown"/ bar x="cat" colour="grey"/ bar x="fish" colour="gold"/ /foo foo bar x="dog" colour="black"/ bar x="cat" colour="white"/ bar x="fish" colour="blue"/ /foo /foobars I want to ENFORCE that every <foo> contains three <bar> children and that "dog", "cat", and "fish" appear each once. It's easy to to say that <bar> must occur max=3 and min=3 but I cannot specify that "dog", "cat", and "fish" appear since I cannot define <bar> more than once in my schema. I get some "duplicate declaration within current scope" error. Now if I re-formed my XML document thusly: foobars foo bar dog>brown</dog cat>grey</cat fish>gold</fish /bar /foo foo bar dog>brown</dog cat>grey</cat fish>gold</fish /bar /foo /foobars It's possible to do because there is only one <bar> and <dog>, <cat>, and <fish> all have different names and I can check that each one occurs once and only once. The thing is if I change my XML I have to change my app, so at the moment my preferred solution is to find a way of writing a schema that works for example #1. Can it be done? |
#4
| |||
| |||
|
|
Yes, you can do this using uniqueness constraints. |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |