1

I have received a specification for a SOAP service where the request that I'm sent will contain the following:

<eventContexts>
    <eventContext name="eventType" value="Unwind"/>
    <eventContext name="referenceId" value="26214"/>
</eventContexts>

I am trying to model this object in the XSD but I'm blocked in the choice of type for the attribute value. As you can see in the above example, it can either be a xs:string (case Unwind) or a xs:long (case 26214).

What type should I choose to make the attribute value accept both xs:string and xs:long? So far I can think of two things:

1) Should I create two different attributes, e.g. stringValue and longValue:

<xs:complexType name="XmlEventContext">
    <xs:attribute name="name" type="xs:string"/>Sh
    <xs:attribute name="stringValue" type="xs:string" minOccurs="0"/>
    <xs:attribute name="longValue" type="xs:long" minOccurs="0"/>   
</xs:complexType>

... and let the client send me the good value in the good attribute? (This looks ugly to me but I'm not a big expert).

2) Should I extend the auto-generated class XmlEventContext with a custom class that takes the value as xs:string and then tries to cast it to xs:long?

public class XmlEventContextComplete extends XmlEventContext {
    //code to manage a property referenceId which can either be long or string
}

3) Any other more elegant suggestion?

Thanks in advance!

Matteo NNZ
  • 11,930
  • 12
  • 52
  • 89

1 Answers1

0

You want a type that can be either a long or a specific enumerated string.

This should cover that case:

<xs:complexType name="xmlEventContext">
    <xs:attribute name="name" type="xs:string" />
    <xs:attribute name="value" type="longOrUnwind" />
</xs:complexType>

<xs:simpleType name="longOrUnwind">
    <xs:union memberTypes="xs:long unwindConstant" />
</xs:simpleType>

<xs:simpleType name="unwindConstant">
    <xs:restriction base="xs:string">
        <xs:enumeration value="Unwind" />
    </xs:restriction>
</xs:simpleType>
xtratic
  • 4,600
  • 2
  • 14
  • 32