Parse XML and get data inside value attribute of tags
<p>I am new to XML parsing. I have read about DOM and SAX parser and tried a few sample implementation. However, I am unable to parse the following XML data</p>

<pre><code>&lt;?xml version="1.0" ?&gt;
&lt;collection&gt;
&lt;action value="submit"/&gt;
&lt;protocol_version value="1"/&gt;
&lt;reponse value="Success"/&gt;
&lt;batch&gt;
    &lt;sample&gt;
        &lt;count value="1"/&gt;
        &lt;count2 value="2"/&gt;
        &lt;count3 value="3"/&gt;
    &lt;/sample&gt;
    &lt;sample_2&gt;
        &lt;date value="10/10/2010"/&gt;
        &lt;page value="SampleData"/&gt;
        &lt;track value="123123123"/&gt;
        &lt;same value="1.00"/&gt;
        &lt;data&gt;
            &lt;first_name value="Jeffrey"/&gt;
            &lt;SSID value="1231231231"/&gt;
            &lt;last_name value="Chuckle"/&gt;
            &lt;field1 value="123123123"/&gt;
            &lt;field2 value="Sam E. Bonzella"/&gt;
            &lt;field3 value="SOME VALUE"/&gt;
            &lt;field4 value="SOME VALUE 2"/&gt;
            &lt;field5 value="TEXT"/&gt;
            &lt;field6 value="12312"/&gt;
        &lt;/data&gt;
    &lt;/sample_2&gt;
&lt;/batch&gt;
&lt;/collection&gt;
</code></pre>

<p>Below is sample code I tried implementing but it requires repetative code and also, the data is not organised. I also tried JAXB parser but was unable to fetch the value attribute.</p>

<pre><code>public class test {
public static void main(String[] args){

    try {
        File inputFile = new File("staff.xml");
        DocumentBuilderFactory dbFactory
                = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        Document doc = dBuilder.parse(inputFile);
        doc.getDocumentElement().normalize();
        System.out.println("Base :"
                + doc.getDocumentElement().getNodeName());
        NodeList nList = doc.getElementsByTagName("action");
        for (int temp = 0; temp &lt; nList.getLength(); temp++) {
            Node nNode = nList.item(temp);
            System.out.println("Element :"
                    + nNode.getNodeName());
            if (nNode.getNodeType() == Node.ELEMENT_NODE) {
                Element eElement = (Element) nNode;
                System.out.println("Action : "
                        + eElement.getAttribute("value"));
            }
        }
        nList = doc.getElementsByTagName("transaction_count");
        for (int temp = 0; temp &lt; nList.getLength(); temp++) {
            Node nNode = nList.item(temp);
            System.out.println("Element :"
                    + nNode.getNodeName());
            if (nNode.getNodeType() == Node.ELEMENT_NODE) {
                Element eElement = (Element) nNode;
                System.out.println("transaction_count : "
                        + eElement.getAttribute("value"));
            }
        }


    } catch (Exception e) {
        e.printStackTrace();
    }
}
}
</code></pre>

<p>Ideally I wish to parse the data to an array or may be Map.</p>