Created
April 30, 2015 13:59
-
-
Save jonashackt/ae9bf0e6465a8a63b5be to your computer and use it in GitHub Desktop.
Append org.w3c.dom.Document as org.w3c.dom.Element to another org.w3c.dom.Document
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Document you want 2 append | |
Document document = ...; | |
// Create the Document | |
DocumentBuilderFactory docBuilderfactory = DocumentBuilderFactory.newInstance(); | |
DocumentBuilder docBuilder = docBuilderfactory.newDocumentBuilder(); | |
Document document2Append2 = docBuilder.newDocument(); | |
// Copy the Document as ChildElement under a new Element | |
Element rootElement = document2Append2.createElement("root"); | |
document2Append2.appendChild(rootElement); | |
Node importedNode = document2Append2.importNode(document.getDocumentElement(), true); | |
document2Append2.getDocumentElement().appendChild(importedNode); | |
//... Mind the Exception-Handling :) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment