java - How to remove the tag in XML using JAXB -


i'm using jaxb convert java object xml file.

in xml file, need remove tag without using xslt .

for example :remove tag orders

<order_list>   <orders>     <orderid>12324<orderid>   </orders> </order_list> 

excepted result :

<order_list>    <orderid>12324<orderid> </order_list> 

i can suggest "naive" approach.

the wrapper tag orders can configured using jaxb annotation @xmlelementwrapper. so, can create 2 models: 1 contain tag, not. can use model contains tag parse data, copy data model not contain tag , use serialize.

@xmlrootelement(name = "index-annotations") public class orderlist {    private collection<integer> orderids;     @xmlelement(name = "orderid", type = integer.class)    public collection<integer> getorderid() {        return orderids;    } }   @xmlrootelement(name = "index-annotations") public class outputorderlist extends orderlist {    @override    @xmlelement(name = "orderid", type = integer.class)    @xmlelementwrapper(name="orders")    public collection<integer> getorderid() {        return orderids;    } } 

obviously solution contains kind of duplicate code, better configuring 2 schemas using xml because of compile time validation of annotations validity.


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -