views:

28

answers:

1

How would one go about defining something like this in an xsd?

<start>
    <request type="typeA">
        <elementOnlyFoundInA />
    </request>
    <request type="typeB">
        <elementOnlyFoundInB />
    </request>
</start>

I ran xsd.exe just to get an idea of what it might look like, but it does not appear recognize the relationships between the value of type and the contents of the request. Is it even possible to define contents based on an attribute like this in an xsd file?

+3  A: 

XML Schema doesn't currently support anything like this - you cannot make structure dependent on the contents of other attributes or elements.

A new XML schema version in the works might offer something in that direction, but it's far from being accepted and implemented at this time.

If you need this kind of XML validation, you need to turn to Schematron for now.

marc_s
Good call - not enough people know about Schematron it seems.
Nic Gibson
Since this is the first time I have worked on an xsd... no I have not heard of Schematron, I shall give it a look though.
SeanJA