SeanJA
SeanJA

Reputation: 10384

Defining xml in an xsd where an attribute determines the possible contents

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?

Upvotes: 5

Views: 169

Answers (1)

marc_s
marc_s

Reputation: 755381

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.

Upvotes: 4

Related Questions