List of utility methods to do XML Document Clone
void | copy(Document from, Document to) copy Element fromRootElem = from.getDocumentElement(); Element toRootElem = to.getDocumentElement(); Node childNode, importedNode; NodeList toChildNodes = fromRootElem.getChildNodes(); for (int i = 0; i < toChildNodes.getLength(); i++) { childNode = toChildNodes.item(i); importedNode = to.importNode(childNode, true); toRootElem.appendChild(importedNode); ... |
void | copyChildren(Document new_doc, Node node, Node new_node) copy Children final NodeList children = node.getChildNodes(); Node new_child; for (int i = 0; i < children.getLength(); i++) { final Node child = children.item(i); if (child == null) { continue; switch (child.getNodeType()) { ... |
void | copyChildren(Element from, Element to, Document doc) copy Children Node child = from.getFirstChild();
while (child != null) {
to.appendChild(doc.importNode(child, true));
child = child.getNextSibling();
|
void | copyChildren(final Document newDoc, final Node node, final Node newNode) copy Children final NodeList children = node.getChildNodes(); Node newChild; for (int i = 0; i < children.getLength(); i++) { final Node child = children.item(i); if (child == null) { continue; switch (child.getNodeType()) { ... |
Document | copyDocument(Document document) copy Document Node n = document.getDocumentElement().cloneNode(true);
Document result = newDocument();
result.adoptNode(n);
result.appendChild(n);
return result;
|
void | copyDocument(Document from, Document to) copy Document Node node = to.importNode(from.getDocumentElement(), true); to.getDocumentElement().appendChild(node); |
Document | copyDocument(Document oldDocument, Document newDocument) Copies a document's content to another document (i.e. Node root = oldDocument.getDocumentElement();
Node adoptedRoot = newDocument.adoptNode(root);
newDocument.appendChild(adoptedRoot);
return newDocument;
|
Document | copyDocument(Document source) Clone a Document object. DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
Node originalRoot = source.getDocumentElement();
Document copiedDocument = db.newDocument();
Node copiedRoot = copiedDocument.importNode(originalRoot, true);
copiedDocument.appendChild(copiedRoot);
return copiedDocument;
...
|
void | copyDocument(Element from, Element to, String newNamespace) Copy elements from one document to another attaching at the specified element and translating the namespace. Document doc = to.getOwnerDocument(); NodeList nl = from.getChildNodes(); int length = nl.getLength(); for (int i = 0; i < length; i++) { Node node = nl.item(i); Node newNode = null; if (Node.ELEMENT_NODE == node.getNodeType()) { Element oldElement = (Element) node; ... |
void | copyDocumentNode(Node source, Document target) Copy a Node from one source document, adding it to the document root of a different, target Document Node node = target.importNode(source, true); target.getDocumentElement().appendChild(node); |