Converting Java Object to XML in the order of Schema xml -
i have java object
@xmlrootelement public class customer { private string name; private list<phonenumber> phonenumbers = new arraylist<phonenumber>(); private string id; private date startdate; private date enddate; public string getname() { return name; } public void setname(string name) { this.name = name; } @xmlelement(name = "phone-number") public list<phonenumber> getphonenumbers() { return phonenumbers; } public void setphonenumbers(list<phonenumber> phonenumbers) { this.phonenumbers = phonenumbers; } }
i want define schema xml (customer.xsd) should used set order of tags while generating xml, object xml generated should below in different order compared object members order.
<customer> <startdate></startdate> <enddate></enddate> <name></name> <id></id> <phonenumbers></phonenumbers> </customer>
both marshalling , unmarshalling code should based on same schema xml.
can me how create schema , how achieve ordering??
you have 2 choices:
- in java object can define
@xmltype(proporder={<order of elements>})
refer here more details. - second approach (using xsd), can define xsd this:
<xsd:element name="customer"> <xsd:complextype > <xsd:sequence> <xsd:element name="name" type="xsd:string" /> <xsd:element name="id" type="xsd:string" /> <xsd:element name="startdate" type="xsd:string" /> <xsd:element name="enddate" type="xsd:int" /> <xsd:element name="phonenumbers" type="xsd:string" minoccurs="0" maxoccurs="unbounded" /> </xsd:sequence> </xsd:complextype> </xsd:element>
in xsd can order elements inside <xsd:sequence>
please note, have not tried xsd example, added reference.
Comments
Post a Comment