📄 e525. copying a subtree of nodes in a dom document.txt
字号:
// Obtain an element; the following method is implemented in
// e510 The Quintessential Program to Create a DOM Document from an XML File
Document doc = parseXmlFile("infilename.xml", false);
NodeList list = doc.getElementsByTagName("entry");
Element element = (Element)list.item(0);
// Make a copy of the element, including any child nodes
Element dup = (Element)element.cloneNode(true);
// Insert the copy immediately after the cloned element
element.getParentNode().insertBefore(dup, element.getNextSibling());
This is the sample input for the example:
<root>
<entry attr="value">
a<i>b</i>c
</entry>
</root>
This is the resulting XML:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<entry attr="value">
a<i>b</i>c
</entry><entry attr="value">
a<i>b</i>c
</entry>
</root>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -