Validate XML element tag
<p>I am having a XML file like </p>

<pre><code>&lt;parent&gt;
  &lt;child1&gt;
   &lt;child2&gt;
     &lt;name&gt;name&lt;/name&gt;
     &lt;value&gt;
     &lt;item&gt;value&gt;&lt;/item&gt;
    &lt;/value&gt;
  &lt;/child2&gt;
 &lt;/child1&gt;
  &lt;child1&gt;
   &lt;value&gt;
     &lt;item&gt;value&gt;&lt;/item&gt;
    &lt;/value&gt;
 &lt;/child1&gt;
&lt;/parent&gt;
</code></pre>

<p>Here i need to check, whether child2 node is missing or not. </p>

<p>My java code is like</p>

<pre><code>File xmlfile = new File ("sample.xml");
DocumentBuilderFactory dbfaFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = dbfaFactory.newDocumentBuilder();
Document doc = documentBuilder.parse(xmlfile);
NodeList child1= doc.getElementsByTagName("child1");
for( int i=0; i&lt;child1.getLength(); i++)
{
NodeList child1= doc.getElementsByTagName("child1");
if(!doc.getElementsByTagName("child2").equals(null))
{
System.out.println("Not Equal to null");

                else
                {
                    System.out.println("Equal to null");
                }
}
</code></pre>

<p>But every time i am getting Not Equal to null, even though child2 node is missing in the XML.</p>

<p>Here child2 is missing</p>

<pre><code>&lt;child1&gt;
   &lt;value&gt;
     &lt;item&gt;value&gt;&lt;/item&gt;
    &lt;/value&gt;
 &lt;/child1&gt;
</code></pre>

<p>Thanks.</p>
