2

I have an XML doc-

<?xml version="1.0" encoding="UTF-8" standalone="no" ?> 
<Companies>
<company id="ABHISHEK">
    <staff id="1">
        <firstname>yong</firstname>
        <lastname>mook kim</lastname>
        <nickname>mkyong</nickname>
        <salary>100000</salary>
    </staff>
</company>
<company id="RAHUL">
    <staff id="2">
        <firstname>yong</firstname>
        <lastname>mook kim</lastname>
        <nickname>mkyong</nickname>
        <salary>100000</salary>
    </staff>
</company>
</Companies>

Now I want to swap the category ABHISHEK and RAHUL so that in xml , Compay with ID RAHUL comes first then ABHISHEK. Is there any existing API to do it?

Abhishek Choudhary
  • 8,255
  • 19
  • 69
  • 128

1 Answers1

3

Yes, have a look at the org.w3c.dom package and the Node interface.

If the order of <company> elements depend on some sort order, perhaps XSLT is a better alternative.

forty-two
  • 12,204
  • 2
  • 26
  • 36