title: Why am I required to verify if a node is an instance of an Element?
body: <p>I have made a simple XML file and I am trying to print the child nodes. I have managed to do it but it only works if I verify first that my <em>person</em> node is an instance of Element. I thought that elements are instance of nodes.</p>
  <p>What I do in the code below is just take each item from a NodeList called <em>nameList</em> and turn the into an element so that I can print them to standard output. Why do I get an exception(java.lang.ClassCastException) if I don't check if <em>person</em> is an instance of Element?</p>
  <p>Thanks in advance!</p>
  <pre><code>// Get the child nodes tag names from the root element
      System.out.println(&quot;These are the names in child nodes: &quot;);
      NodeList nameList = element.getChildNodes();
      for(int i = 0; i &lt; nameList.getLength(); i++) {
          Node person = nameList.item(i);
          if (person instanceof Element){
              Element name = (Element)person;
              System.out.println(name);
          }
      }
  </code></pre>