Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

xml

xsd

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?

like image 628
SeanJA Avatar asked Oct 15 '22 07:10

SeanJA


1 Answers

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.

like image 120
marc_s Avatar answered Oct 18 '22 13:10

marc_s