save xml object so that elements are in sorted order in saved xml file

Posted by scot on Stack Overflow See other posts from Stack Overflow or by scot
Published on 2010-05-25T05:33:36Z Indexed on 2010/05/25 5:51 UTC
Read the original article Hit count: 569

Filed under:
|
|
|

Hi ,

I am saving a xml document object and it is saved in a xml file as shown below .

<author name="tom" book="Fun-II"/>
<author name="jack" book="Live-I"/>
<author name="pete" book="Code-I"/>
<author name="jack" book="Live-II"/>
<author name="pete" book="Code-II"/>
<author name="tom" book="Fun-I"/>

instead i want to sort the content in document object so that when i persist the object it is saved by grouping authors then book name as below:

<author name="jack" book="Live-I"/>
<author name="jack" book="Live-II"/>
<author name="pete" book="Code-I"/>
<author name="pete" book="Code-II"/>
<author name="tom" book="Fun-I"/>
<author name="tom" book="Fun-II"/>

I use apache xml beans..any ideas on how to achieve this?

thanks.

© Stack Overflow or respective owner

Related posts about java

Related posts about Xml