Sorting Elements based on Attribute Value in Java -


I am trying to sort the node in the nodelist based on the item id. Looks like XML

  & lt; Order & gt; & Lt; Lines & gt; & Lt; Line line not = "1" & gt; & Lt; Item ID = "Item 1" /> & Lt; / Line & gt; & Lt; Line Line = "2" & gt; & Lt; Item ID = "Item A4" /> & Lt; / Line & gt; & Lt; Line Line = "3" & gt; & Lt; Item ID = "ItemA7" /> & Lt; / Line & gt; & Lt; Line Line = "4" & gt; & Lt; Item id = "itembie 3" /> & Lt; / Line & gt; & Lt; Line Line = "5" & gt; & Lt; Item ID = "Item C1" /> & Lt; / Line & gt; & Lt; / Lines & gt; & Lt; / Order & gt;  

So after sorting XML,

   & Lt; / Line & gt; & Lt; Line Line = "5" & gt; & Lt; Item ID = "Item A4" /> & Lt; / Line & gt; & Lt; Line Line = "4" & gt; & Lt; Item ID = "ItemA7" /> & Lt; / Line & gt; & Lt; Line Line = "3" & gt; & Lt; Item id = "itembie 3" /> & Lt; / Line & gt; & Lt; Line Line = "2" & gt; & Lt; Item ID = "Item C1" /> & Lt; / Line & gt; & Lt; / Lines & gt; & Lt; / Order & gt;  

I have written for this argument

  Maps & lt; String, Element & gt; MapIDAndLine = New Hashmop & lt; String, Element & gt; (); Node list nlLine = doc.getElementsByTagName ("line"); (Element LLN = (element) elLine.item (cntLine); Element LITIM = ALLine.Get Child Element ("item") for (int cntLine = 0; cntLine & lt; nlLine.getLength (); cntLine ++); string sItemID = elItem.getAttribute ( "ID"); if (! Mapaidiandellaincontenski (the Itamaidi)) {mapIDAndLine.put (Saitiamaidi, Ellain);}} map & lt; string, string & gt; Trymark = new Trymark & ​​lt; String, String & gt; (Map ID Endline);  

I get a map where all keys (Item ID ED) are sorted

Now I can iterate through the tree map and I can get this line and the doctor has removed the original lines.

Please tell me that I am doing something wrong here or there is a better way to do this.

Thanks in advance


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -