📄 e526. copying a subtree of nodes from one dom document to another.txt
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -