Inefficient XML parsing in Java
<p>I have a XML like this:</p>

<pre><code>&lt;thoughts&gt;
    &lt;thought&gt;
        &lt;id&gt;1&lt;/id&gt;
        &lt;category&gt;Leadership&lt;/category&gt;
        &lt;what&gt;sometext&lt;/what&gt;            
        &lt;who&gt;sometext&lt;/who&gt;
    &lt;/thought&gt;
    &lt;thought&gt;
        &lt;id&gt;2&lt;/id&gt;
        &lt;category&gt;Leadership&lt;/category&gt;
        &lt;what&gt;sometext&lt;/what&gt;            
        &lt;who&gt;sometext&lt;/who&gt;
    &lt;/thought&gt;
    ... 100's of with category Leadership
    &lt;thought&gt;
        &lt;id&gt;1&lt;/id&gt;
        &lt;category&gt;Love&lt;/category&gt;
        &lt;what&gt;sometext&lt;/what&gt;            
        &lt;who&gt;sometext&lt;/who&gt;
    &lt;/thought&gt;
    &lt;thought&gt;
        &lt;id&gt;2&lt;/id&gt;
        &lt;category&gt;Love&lt;/category&gt;
        &lt;what&gt;sometext&lt;/what&gt;            
        &lt;who&gt;sometext&lt;/who&gt;
    &lt;/thought&gt;
    ... 100's of with category Love

    ... and so on up to about ten categories
&lt;/thoughts&gt;
</code></pre>

<p>I am parsing this xml in java for a particular category and id in android.
Here is my code:</p>

<pre><code>String id= "100",category="Love";// for example
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(getResources().openRawResource(R.raw.thoughts));
doc.getDocumentElement().normalize();

// Log.d(LOG,"root: " + doc.getDocumentElement().getNodeName());
NodeList nList = doc.getElementsByTagName("thought");

for (int temp = 0; temp &lt; nList.getLength(); temp++) {
    org.w3c.dom.Node nNode = nList.item(temp);
    Element eElement = (Element) nNode;
    if (nNode.getNodeType() == Node.ELEMENT_NODE &amp;&amp; getTagValue("id", eElement).contains(id) &amp;&amp; getTagValue("category", eElement).contains(category)) {
        Log.d("THOUGHTSERVICE", "getTagValue(\"what\", eElement):"+getTagValue("what", eElement));
        what = getTagValue("what", eElement);
        who = getTagValue("who", eElement);
    }
}
</code></pre>

<p>The problem is: this is kind of brute force. Can you suggest some other method? May be give an example.</p>

<p>Thanks in advance</p>
