Say I have the following XML document:
<root>
<genres>
<genre name="comedy" />
<genre name="academic" />
</genres>
<authors>
<author name="Thomson">
<writings>
<writing genre="academic">The text book</writing>
<writing genre="comedy">The worst comedy</writing>
<writings>
</author>
</authors>
<readers>
<reader name="Phil">
<read writenBy="Thomson">The text book</read>
</reader>
<reader name="John" />
</readers>
</root>
As you can see, a 'reader' element may not have 'read' childs.
However, I want the validation process to make sure there aren't entries like:
<reader name="Paul">
<read writtenBy="Thomson">A writing the author never wrote</read>
</reader>
What I can do is limit the values an attribute can take based on previously defined attributes by using keys and keyrefs (see accepted answer). Based on that I can make sure the 'writtenBy' attribute actually refers to an author's name, or a writing's genre attribute comes from a previously defined genre.
I know you can hard code enumerations on an XSD document (see accepted answer).
Also, you may use assertions (in XSD 1.1) to have more flexible enumerations based on information contained on the XML (see accepted answer).
But I can't use these apporaches because they are hard coded. Is there a way to do a similar check for element values like I'm currently doing it with attribute values?