How do I resolve two nodes which have the same name but under different parents? <pre><code> &lt;PublicRecords&gt; &lt;USBankruptcies&gt; &lt;USBanktruptcy&gt;...&lt;USBankruptcy&gt; &lt;CourtId&gt;...&lt;/CourtId&gt; &lt;USBanktruptcy&gt;...&lt;USBankruptcy&gt; &lt;CourtId&gt;...&lt;/CourtId&gt; &lt;/USBankruptcies&gt; &lt;USTaxLiens&gt; &lt;USTaxLien&gt;...&lt;USTaxLien&gt; &lt;CourtId&gt;...&lt;/CourtId&gt; &lt;USTaxLien&gt;...&lt;USTaxLien&gt; &lt;CourtId&gt;...&lt;/CourtId&gt; &lt;/USTaxLiens&gt; &lt;USLegalItems&gt; &lt;USLegalItem&gt;&lt;USLegalItem&gt; &lt;CourtId&gt;&lt;/CourtId&gt; &lt;USLegalItem&gt;&lt;USLegalItem&gt; &lt;CourtId&gt;&lt;/CourtId&gt; &lt;/USLegalItems&gt; &lt;/PubicRecords&gt; </code></pre> <p>I am using a combination of doc and xpath objects to extract the attributes and node contents. </p> <pre><code> NodeList bp = doc.getElementsByTagName("USBankruptcy"); NodeList nl = doc.getElementsByTagName("CourtId"); long itrBP; for (itrBP = 0; itrBP &lt; bp.getLength(); itrBP++ ) { Element docElement = (Element) bp.item(itrBP); Element courtElement = (Element) nl.item(itrBP); NodeList df = docElement.getElementsByTagName("DateFiled"); if(df.getLength() &gt; 0) { dateFiled = nullIfBlank(((Element)df.item(0)).getFirstChild().getTextContent()); dateFiled = df.format(dateFiled); } </code></pre> <p>But, when I say get elements of tag name CourtID, it will get all the CourtIDs, not just the ones under USBankruptcy.</p> <p>Is there any way to specify the parent? </p> <p>I tried NodeList nl = doc.getElementsByTagName("USBankruptcies/CourtId");</p> <p>It gave me a dom error on run time.</p>