本文介绍了从JAX-WS生成XSD时如何避免XSD序列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我注释了java类
@javax.xml.bind.annotation.XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class UserdataType {
String username;
String street;
String address;
它将生成为
<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"/>
因此,默认情况下,JAX-WS总是在XSD文件中生成序列".
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={})
然后它将生成xs:all
(无序)而不是序列.
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>
这篇关于从JAX-WS生成XSD时如何避免XSD序列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!