title: How can I insert content into a DOM document using EntityReferences?
body: <p>I'm using org.w3c.dom.Document in Java and inserting EntityReference nodes. These are added OK but are stripped out by javax.xml.transform.Transformer. This code explains what I mean:</p>
  
  <pre><code>    DOMImplementation dmi = DOMImplementationRegistry.newInstance().getDOMImplementation("");
      Document doc = dmi.createDocument(null, "html", null);
      doc.getDocumentElement().appendChild(doc.createTextNode("AT"));
      doc.getDocumentElement().appendChild(doc.createEntityReference("amp"));
      doc.getDocumentElement().appendChild(doc.createTextNode("T"));
      Transformer tr = TransformerFactory.newInstance().newTransformer();
      tr.setOutputProperty(OutputKeys.METHOD, "html");
      tr.transform(new DOMSource(doc), new StreamResult(System.out));
  </code></pre>
  
  <p>The output of this is </p>
  
  <pre><code>&lt;html&gt;ATT&lt;/html&gt;
  </code></pre>
  
  <p>and I want </p>
  
  <pre><code>&lt;html&gt;AT&amp;amp;T&lt;/html&gt;
  </code></pre>
  
  <p>I know that if I do <code>doc.createTextNode("AT&amp;T")</code> directly it will escape the '&amp;' for me, so I'm looking for a way to</p>
  
  <ul>
  <li>preserve my EntityReferences, or</li>
  <li>let me look up the defined Entities, or</li>
  <li>fill in the Entity's text as a child of the EntityReference.</li>
  </ul>
  
  <p>I have to deal with the entity reference names because I have to implement an interface that looks like</p>
  
  <pre><code>interface Xxx {
   void addText(String text);
   void addEntity(String entName);
   ...
  }
  </code></pre>