Java tutorial
//package com.java2s; /******************************************************************************* * Copyright (c) 2015 CA. All rights reserved. * * This source file is licensed under the terms of the Eclipse Public License 1.0 * For the full text of the EPL please see https://www.eclipse.org/legal/epl-v10.html *******************************************************************************/ import org.w3c.dom.Document; import org.w3c.dom.Node; public class Main { /** * Appends two documents * * @param curDoc source document * @param appendDoc document to append to source * @param eleNameToAdd element tag name in source to which the appendDoc has to be appended as a child * @throws Exception */ public static void appendDocs(Document curDoc, Document appendDoc, String eleNameToAdd) throws Exception { Node importNode = curDoc.importNode(appendDoc.getDocumentElement(), true); curDoc.getElementsByTagName(eleNameToAdd).item(0).appendChild(importNode); } }