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]
# 1

What have you tried and what are you stuck on. You will get nothing but abuse from people on here asking such blatent "DO MY WORK" questions.

ita6cgra at 2007-7-29 12:00:24 > top of Java-index,Java Essentials,New To Java...
# 2

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());}

}

}

dkpadhya at 2007-7-29 12:00:24 > top of Java-index,Java Essentials,New To Java...
# 3

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.

ita6cgra at 2007-7-29 12:00:24 > top of Java-index,Java Essentials,New To Java...
# 4

can u send me some sample files

dkpadhya at 2007-7-29 12:00:24 > top of Java-index,Java Essentials,New To Java...
# 5

some sample ex or the logic how to go about this

dkpadhya at 2007-7-29 12:00:24 > top of Java-index,Java Essentials,New To Java...