Reputation: 1218
Maybe my vocabulary is somehow wrong:
I would like to create an xsd, that defines one of many 'custom-types' for an element.
My xml should have the root with alsways the same 'someInfo' an then one element that is a kind of
CustomTypeA or CustomTypeB.
The XML should look like this:
<xml>
<someInfo>whatever is important</someInfo>
<info type="CustomTypeA">
<CustomTypeA-1>F1</CustomTypeA-1>
<CustomTypeA-2>F2</CustomTypeA-2>
</info>
</xml>
or in other cases, where info should be if an other CustomType:
<xml>
<someInfo>whatever is important in an other case</someInfo>
<info type="CustomTypeB">
<CustomTypeB-1 attr1="someAttribute">F1</CustomTypeB-1>
</info>
</xml>
Upvotes: 0
Views: 62
Reputation: 9279
I did some conditional type assignment here yesterday. More information about conditional type assignment can be read at the last example here.
Upvotes: 0
Reputation: 163342
If you want the type of an element to depend on the value of one of its attributes, you have two options:
(a) use "xsi:type" as the attribute name, its value being the name of a type in the schema
(b) use XSD 1.1 with the new feature of conditional type assignment. If you're able to use XSD 1.1 that's the best solution, but not everyone supports it yet.
Upvotes: 1