xml file Sorting
Hi
i have a xml file as
<Order>
<ListOfItems>
<Item>
<ItemNo>1</ItemNo>
<ItemPrice>100</ItemPrice>
<Quantity>5</Quantity>
</Item>
<Item>
<ItemNo>2</ItemNo>
<ItemPrice>200</ItemPrice>
<Quantity>4</Quantity>
</Item>
<Item>
<ItemNo>3</ItemNo>
<ItemPrice>400</ItemPrice>
<Quantity>3</Quantity>
</Item>
<Item>
<ItemNo>4</ItemNo>
<ItemPrice>500</ItemPrice>
<Quantity>2</Quantity>
</Item>
<Item>
<ItemNo>5</ItemNo>
<ItemPrice>300</ItemPrice>
<Quantity>1</Quantity>
</Item>
</ListOfItems>
</Order>
Pls help me in designing a code with help of dom4j so that
it'll rearrenge the <item>...</item> elements in ascending order of <Quantity>
pls...
[982 byte] By [
dkpadhya] at [2007-11-27 10:56:02]

i made code like this
its not giving any error but not sorting .
i think... problem with my logic but ....
can u pls modify or suggest something so that i'll be able to complete.
--
public class OrderItemDetail{
public static void main(String[] args) {
try{
SAXReader saxReader = new SAXReader();
Document document = saxReader.read("OrderItem.xml");
Element root = document.getRootElement();
List list = document.selectNodes("/*/ItemPrice");
DocumentHelper.sort(list,"Quantity");
XMLWriter output = new XMLWriter(
new FileWriter( new File("D:/OrderItem.xml") ));
output.write( document );
output.close();
}
catch(DocumentException e){System.out.println(e.getMessage());}
catch(IOException e){System.out.println(e.getMessage());}
}
}
Firstly use code tags..... Looking at your code it seems you do nothing to the data which is ouput to the file.
You are reading the file. Listing all the nodes [DO WORK HERE] and outputting the original document to the output file...... You need to change what you output to the file.