how to sort xml code in ascending order in java
<p>Below is my XML code i need to display the 'node name' in ascending order. </p>

<p>XML :</p>

<pre><code>&lt;node label="Tree Data"&gt;
&lt;node name="View" type="Page"&gt;
&lt;node name="Organisational Structure" type="Page"/&gt;
&lt;node name="Experience" type="Page"/&gt;
&lt;node name="Expertise" type="Language"&gt;
&lt;node name="Flex" type="Language"/&gt;
&lt;node name="Android" type="Language"/&gt;
&lt;node name="Java" type="Language"/&gt;
&lt;/node&gt;
&lt;node name="Project" type="Project"&gt;
&lt;node name="Sabre" type="Project"/&gt;
&lt;node name="Android Project" type="Project"/&gt;
&lt;node name="Media Framework" type="Project"/&gt;
&lt;node name="CCD" type="Project"/&gt;
&lt;node name="Redbus" type="Project"/&gt;
&lt;node name="India Today" type="Project"/&gt;
&lt;node name="Money Control" type="Project"/&gt;
&lt;/node&gt;
&lt;/node&gt;
&lt;node name="Reorganize" type="Action"/&gt;
&lt;node name="Add New Employee" type="Action"&gt;
&lt;node name="Dir" type="Page"/&gt;
&lt;node name="P.M" type="Page"/&gt;
&lt;node name="S.E" type="Page"/&gt;
&lt;node name="JUN" type="Page"/&gt;
&lt;node name="EMP" type="Page"/&gt;
&lt;/node&gt;
&lt;node name="Add Project Members" type="Action"/&gt;
&lt;/node&gt;
</code></pre>

<p>Following is my java code :</p>

<p>JAVA CODE :</p>

<pre><code>import java.io.IOException;
        import java.io.StringWriter;
        import java.net.URL;
        import java.util.ArrayList;
        import java.util.Collections;
        import java.util.List;

        import javax.xml.parsers.DocumentBuilder;
        import javax.xml.parsers.DocumentBuilderFactory;
        import javax.xml.parsers.ParserConfigurationException;
        import javax.xml.transform.OutputKeys;
        import javax.xml.transform.Transformer;
        import javax.xml.transform.TransformerException;
        import javax.xml.transform.TransformerFactory;
        import javax.xml.transform.dom.DOMSource;
        import javax.xml.transform.stream.StreamResult;

        import org.w3c.dom.Document;
        import org.w3c.dom.Element;
        import org.w3c.dom.NamedNodeMap;
        import org.w3c.dom.Node;
        import org.w3c.dom.NodeList;
        import org.xml.sax.InputSource;
        import org.xml.sax.SAXException;

        import android.os.Bundle;
        import android.app.Activity;
        import android.view.Menu;

        public class MainActivity extends Activity {

            Document dom;

            public MainActivity() {
                MainActivity();

                ArrayList&lt;Element&gt; listGroup = getGroups();

            }




            private ArrayList getGroups() {
                try {
                    Element documentElement = (Element) dom.getDocumentElement();
                    System.out.println("root element is :"+documentElement.getNodeName());
                    NodeList childNodes = documentElement.getElementsByTagName("node");

                    for (int i = 0; i &lt; childNodes.getLength(); i++) {

                        if (childNodes.item(i).getNodeType() == Node.ELEMENT_NODE) {
                            Element element = (Element) childNodes.item(i);
                            if(((Element) childNodes.item(i)).hasAttribute("name")) {
                            String name = element.getAttribute("name");
                            String type = element.getAttribute("type");
                            System.out.println("name : " + name);
                            System.out.println("type : " + type);
                        }}
                    }
                } catch (Exception e) {
                }
                return null;

            }

            private void MainActivity() {
                DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();


                try {
                    String sURL = "huhhadjdhjshdjks.com";
                    URL url = new URL(sURL);
                    DocumentBuilder db = dbf.newDocumentBuilder();

                    dom = db.parse(new InputSource(url.openStream()));

                } catch (ParserConfigurationException pce) {
                    pce.printStackTrace();
                } catch (SAXException se) {
                    se.printStackTrace();
                } catch (IOException ioe) {
                    ioe.printStackTrace();
                }
            }
        }
</code></pre>

<p>I am getting the following output :</p>

<p>logcat : </p>

<pre><code>01-31 17:45:59.330: I/System.out(1871): root element is :node
01-31 17:45:59.340: I/System.out(1871): name : View
01-31 17:45:59.360: I/System.out(1871): type : Page
01-31 17:45:59.380: I/System.out(1871): name : Organisational Structure
01-31 17:45:59.380: I/System.out(1871): type : Page
01-31 17:45:59.400: I/System.out(1871): name : Experience
01-31 17:45:59.400: I/System.out(1871): type : Page
01-31 17:45:59.400: I/System.out(1871): name : Expertise
01-31 17:45:59.400: I/System.out(1871): type : Language
01-31 17:45:59.400: I/System.out(1871): name : Flex
01-31 17:45:59.410: I/System.out(1871): type : Language
01-31 17:45:59.410: I/System.out(1871): name : Android
01-31 17:45:59.420: I/System.out(1871): type : Language
01-31 17:45:59.420: I/System.out(1871): name : Java
01-31 17:45:59.430: I/System.out(1871): type : Language
01-31 17:45:59.430: I/System.out(1871): name : Project
01-31 17:45:59.430: I/System.out(1871): type : Project
01-31 17:45:59.440: I/System.out(1871): name : Sabre
01-31 17:45:59.440: I/System.out(1871): type : Project
01-31 17:45:59.440: I/System.out(1871): name : Android Project
01-31 17:45:59.450: I/System.out(1871): type : Project
01-31 17:45:59.450: I/System.out(1871): name : Media Framework
01-31 17:45:59.460: I/System.out(1871): type : Project
01-31 17:45:59.460: I/System.out(1871): name : CCD
01-31 17:45:59.460: I/System.out(1871): type : Project
01-31 17:45:59.460: I/System.out(1871): name : Redbus
01-31 17:45:59.460: I/System.out(1871): type : Project
01-31 17:45:59.460: I/System.out(1871): name : India Today
01-31 17:45:59.480: I/System.out(1871): type : Project
01-31 17:45:59.480: I/System.out(1871): name : Money Control
01-31 17:45:59.489: I/System.out(1871): type : Project
01-31 17:45:59.489: I/System.out(1871): name : Reorganize
01-31 17:45:59.500: I/System.out(1871): type : Action
01-31 17:45:59.500: I/System.out(1871): name : Add New Employee
01-31 17:45:59.500: I/System.out(1871): type : Action
01-31 17:45:59.500: I/System.out(1871): name : Dir
01-31 17:45:59.500: I/System.out(1871): type : Page
01-31 17:45:59.510: I/System.out(1871): name : P.M
01-31 17:45:59.510: I/System.out(1871): type : Page
01-31 17:45:59.510: I/System.out(1871): name : S.E
01-31 17:45:59.530: I/System.out(1871): type : Page
01-31 17:45:59.530: I/System.out(1871): name : JUN
01-31 17:45:59.530: I/System.out(1871): type : Page
01-31 17:45:59.530: I/System.out(1871): name : EMP
01-31 17:45:59.530: I/System.out(1871): type : Page
01-31 17:45:59.530: I/System.out(1871): name : Add Project Members
01-31 17:45:59.530: I/System.out(1871): type : Action
</code></pre>

<p>I need all the name comes in ascending order.
Any help?</p>
