I'm trying to develop a schema that will validate some existing XML files I've inherited. I'd like to have the schema do as much of the validation work as possible. The challenge is that attributes and elements are contingent on the values of other attributes.
The real data is pretty abstract, so I've created some simple examples. Let's say I have the following XML files:
<?xml version="1.0" encoding="UTF-8"?>
<Creature type="human" nationality="British">
<Address>London</Address>
</Creature>
<?xml version="1.0" encoding="UTF-8"?>
<Creature type="animal" species="Tiger">
<Habitat>Jungle</Habitat>
</Creature>
If the creature's "type" is "human", I'll have a "nationality" attribute and an "Address" child element. If the creature's "type" is "animal", I'll have a "species" attribute and a "Habitat" child element. For the purposes of this example, a "human" with a "species" or a "Habitat" would be invalid - as would an "animal" with a "nationality" or "Address".
If "Creature" wasn't the root element, I could probably have two different "Creature" choices below the root element, but I don't see how I can make this work when "Creature" is the root element.
Is there anyway of creating a schema for these files that would only match valid documents? If so, how would I go about it?