开发者

How to define an appropriate complex type?

开发者 https://www.devze.com 2023-03-09 14:46 出处:网络
I have this in my xsd: <xs:element name=\"Parameter\" type=\"complex\"> and I want to define complex like:

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号