title: Java: Create DOM Element from Element, not Document
body: <p>As you know, the proper way to create a Dom Element in Java is to do something like this.</p>
  
  <pre><code>import org.w3c.dom.Document;
  import org.w3c.dom.Element;
  
  Document d;
  Element e;
  
  e = d.createElement("tag");
  </code></pre>
  
  <p>You need to use d to generate the element because it needs a document context. (I'm not 100% sure why, but maybe misunderstanding this is part of my problem)</p>
  
  <p>What I don't understand is, why you can't do something like this </p>
  
  <pre><code>Element e;
  Element e2;
  
  e2 = e.createElement("anothertag");
  </code></pre>
  
  <p>Since e already has the context of d, why can't I create another element from an element? It would certainly simplify my design not having to keep a reference to the Document everywhere.</p>