e526. copying a subtree of nodes from one dom document to another.txt
来自「这里面包含了一百多个JAVA源文件」· 文本 代码 · 共 17 行
TXT
17 行
When copying a subtree of nodes from one document to another, cloning the subtree and then inserting it into the other document will result in a wrong document exception. The subtree of nodes must be imported into the other document using importNode().
// Obtain an element in one document; the following method is implemented in
// e510 The Quintessential Program to Create a DOM Document from an XML File
Document doc1 = parseXmlFile("infilename1.xml", false);
NodeList list = doc1.getElementsByTagName("entry");
Element element = (Element)list.item(0);
// Create another document
Document doc2 = parseXmlFile("infilename2.xml", false);
// Make a copy of the element subtree suitable for inserting into doc2
Node dup = doc2.importNode(element, true);
// Insert the copy into doc2
doc2.getDocumentElement().appendChild(dup);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?