title: How can I clone an entire Document using the Java DOM?
body: <p>I'm looking for a reliable, implementation-independent way to clone an entire Document.  The Javadocs specifically say that calling cloneNode on a Document is implementation-specific.  I've tried passing the Document through a no-op Transformer, but the resulting Node has no owner Document.</p>
  
  <p>I could create a new Document and import the nodes from the old one, but I'm afraid there might be bits of Document metadata that get lost.  Same thing with writing the Document to a string and parsing it back in.</p>
  
  <p>Any ideas?</p>
  
  <p>By the way, I'm stuck at Java 1.4.2, for reasons beyond my control.</p>