DOM PARSING IN ANDROID

 xml eg:

<?xml version="1.0" encoding="UTF-8"?>
<dataset type="receive_data">
   
    <!-- Contains all the routes and pointers to locations -->
    <routes>       
        <route routeid="1" label="Route 1">           
            <location locationid="1" label="location1"></location>       
        </route>   
        <route routeid="2" label="Route 2">       
            <location locationid="1" label="location1"></location>   
        </route>
    </routes>
</dataset>

 //Android code



try {

            InputStream is = this.getResources().openRawResource(R.raw.receive);
            DocumentBuilderFactory factory = DocumentBuilderFactory
                    .newInstance();
            DocumentBuilder db = factory.newDocumentBuilder();
            Document doc = db.parse(is);

            doc.getDocumentElement().normalize();

            NodeList nodelist = doc.getElementsByTagName("routes");

            for (int i = 0; i < nodelist.getLength(); i++) {
                Node node = nodelist.item(i);
                Element ele = (Element) node;
                NodeList nodelist1 = ele.getElementsByTagName("route");
                for (int j = 0; j < nodelist1.getLength(); j++) {
                    Element ele1 = (Element) nodelist1.item(j);
                    String RouteName = ele1.getAttribute("label");
                    Route_ID = ele1.getAttribute("routeid");

                    Log.e("Route", RouteName + Route_ID);
                }

                NodeList nodelist2 = ele.getElementsByTagName("location");

                for (int k = 0; k < nodelist2.getLength(); k++) {
                    Element ele2 = (Element) nodelist2.item(k);
                    String location_id = ele2.getAttribute("locationid");
                    String Location_name = ele2.getAttribute("label");
                    Log.e("Location", location_id + Location_name);

                }

            }

        }