开发者

How can I avoide XSD sequence when generating XSDs from JAX-WS?

开发者 https://www.devze.com 2023-01-30 02:26 出处:网络
When I have annotaded java class like @javax.xml.bind.annotation.XmlRootElement @XmlAccessorType(XmlAccessType.FIELD)

When I have annotaded java class like

@javax.xml.bind.annotation.XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class UserdataType {

    String username;
    String street;
    String address;

it will be generated to

<xs:complexType name="userdataType">
<xs:sequence>
<xs:element name="username" type="xs:string" minOccurs="0"/>
<xs:element name="street" type="xs:string" minOccurs="0"/>
<xs:element name="address" type="xs:string" minOccurs="0"/开发者_Python百科>

So, by default JAX-WS always generates 'sequences' in XSD files.

This forces the clients to take care of the exact order the elements, which is not helpful in some cases.

Is there a way to generate something different then sequences?


Add an XmlType annotation with an empty propOrder, like this:

 @XmlType(propOrder={})

It will then generate an xs:all (which is unordered) instead of a sequence.

<xs:complexType name="userdataType">
  <xs:all>
    <xs:element name="username" type="xs:string" minOccurs="0"/>
    <xs:element name="street" type="xs:string" minOccurs="0"/>
    <xs:element name="address" type="xs:string" minOccurs="0"/>
  </xs:all>
</xs:complexType>
0

精彩评论

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