title: Not able to parse inner elements of XML using DocumentBuilderFactory in Java
body: <p>I'm having a response as XML. I'm trying to parse the XML object to get inner details. Im using DocumentBuilderFactory for this. The parent object is not null, but when I try to get the deepnode list elements, its returning null. Am I missing anything</p>
  
  <p>Here is my response XML</p>
  
  <h2>ResponseXML</h2>
  
  <pre><code>&lt;DATAPACKET REQUEST-ID = "1"&gt;
  &lt;HEADER&gt;        
  &lt;/HEADER&gt;
  &lt;BODY&gt;      
      &lt;CONSUMER_PROFILE2&gt;
          &lt;CONSUMER_DETAILS2&gt;             
              &lt;NAME&gt;David&lt;/NAME&gt;
              &lt;DATE_OF_BIRTH&gt;1949-01-01T00:00:00+03:00&lt;/DATE_OF_BIRTH&gt;
              &lt;GENDER&gt;001&lt;/GENDER&gt;
          &lt;/CONSUMER_DETAILS2&gt;
        &lt;/CONSUMER_PROFILE2&gt;&lt;/BODY&gt;&lt;/DATAPACKET&gt;
  </code></pre>
  
  <p>and Im parsing in the following way</p>
  
  <pre><code>DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
  DocumentBuilder db = dbf.newDocumentBuilder();
  InputSource is = new InputSource();
  is.setCharacterStream(new StringReader(responseXML));
  // Consumer details.
  
  if(doc.getDocumentElement().getElementsByTagName("CONSUMER_DETAILS2") != null) {              
              Node consumerDetailsNode = doc.getDocumentElement().getElementsByTagName("CONSUMER_DETAILS2").item(0); --&gt;This is coming as null                
              dateOfBirth = getNamedItem(consumerDetailsNode, "DATE_OF_BIRTH");                               
              System.out.println("DOB:"+dateOfBirth);             
  
          }
  </code></pre>
  
  <h2>getNamedItem</h2>
  
  <pre><code>private static String getNamedItem(Node searchResultNode, String param) {
      return searchResultNode.getAttributes().getNamedItem(param) != null ? searchResultNode.getAttributes().getNamedItem(param).getNodeValue() : "";
  }
  </code></pre>
  
  <p>Any ideas would be greatly appreciated. </p>