title: Error: org.apache.xerces.dom.DeferredTextImpl cannot be cast to org.w3c.dom.Element
body: <p>XML:</p>
  
  <pre><code>&lt;nativeInformation&gt;
         &lt;detail id="natural:fieldFormat"&gt;A&lt;/detail&gt;
  &lt;/nativeInformation&gt;
  </code></pre>
  
  <p>I am trying to get the "id" value. but keep getting this error: org.apache.xerces.dom.DeferredTextImpl cannot be cast to org.w3c.dom.Element</p>
  
  <p>My code:</p>
  
  <pre><code>  for (int i = 0; i &lt; nodeList.getLength(); i++) {
        String s;
        Node n = nodeList.item(i);         
        Attr attrName = ((Element) n).getAttributeNode("id");          
        if (attrName.getValue()!=null) {
             s = attrName.getValue();
             System.out.println(s);              
        } 
       } 
  </code></pre>
  
  <p>If I write : System.out.println("parent node is "+n.getParentNode()); inside the for loop that will give me,  [detail: null]</p>
  
  <p>Any help will be really appreciated.</p>