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

孤者浪人 提交于 2020-01-04 14:13:43

问题


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"/>

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?


回答1:


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>


来源:https://stackoverflow.com/questions/4407746/how-can-i-avoide-xsd-sequence-when-generating-xsds-from-jax-ws

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!