1

Possible Duplicate:
Control order of XML attributes in outputed file in Java

I have this code:

 Element node = testDoc.createElement("image_file");
 node.setAttribute("id", count);
 node.setAttribute("file_name", fileNameCombinedWithPNG);

My XML has filename before the id, no matter what I do, even when I switch the orders of the set attributes, the output of the XML looks the same, i.e the it's:

image_file filename="xyz" id="1" as but I want is image_file id="1" filename="adfx"
Community
  • 1
  • 1
zoy.khan
  • 87
  • 1
  • 9
  • 4
    XML attributes don't have to be in order. Any tool that depends on the order is buggy. – madth3 Nov 30 '12 at 01:14
  • I want them in order, how can I make it in order sir – zoy.khan Nov 30 '12 at 01:14
  • There are questions here dealing with this: http://stackoverflow.com/q/8087602/422353 http://stackoverflow.com/q/7526062/422353 – madth3 Nov 30 '12 at 01:16
  • Do you really need it to be in order. Attributes can be in any order for xml, so toolkits have their own discretion when rendering xml documents. It appears in the toolkit you are using it is using an ordered list to store the attributes. You may fix it for this list but then the toolkit might swap to a hash set. In other words in trying to fix the order you are creating a lot of pain for yourself. – BevynQ Nov 30 '12 at 01:20
  • @madth3 Make that comment of yours an answer, because it's the correct answer. – Bohemian Nov 30 '12 at 01:21
  • 1
    Flagged as duplicate of http://stackoverflow.com/q/8087602/422353 – madth3 Nov 30 '12 at 01:22
  • I'm still a student guys, I appreciate your help. Now I get it. Long live StackOverflow. :) – zoy.khan Nov 30 '12 at 01:25

0 Answers0