Dominating
Dominating

Reputation: 2930

How to define an appropriate complex type?

I have this in my xsd:

<xs:element name="Parameter" type="complex">

and I want to define complex like:

<xs:simpleType name="complex">
    1 xs:decimal
    2 xs:string
  </xs:simpleType>

So if the value for Parameter is decimal to take decimal and if value is not decimal to assume that value is string. How to declare my complex type?

Upvotes: 1

Views: 122

Answers (1)

Waldheinz
Waldheinz

Reputation: 10487

You'll need a complexType together with a choice to express this:

<xs:complexType name="complex">
   <xs:choice>
      <xs:element name="number" type="xs:decimal"/>
      <xs:element name="string" type="xs:string"/>
   </xs:choice>
</xs:complexType>

Edit: Based on your comments maybe this is worth a try:

<xs:simpleType name="monat">
   <xs:union memberTypes="xs:decimal xs:string"/>
</xs:simpleType>

But JAXB will translate this to String anyway, so there's no benefit from the union, at least with respect to the generated classes. And that you are using JAXB is just a guess.

Upvotes: 2

Related Questions