I having a problem with the cloneNode tag problem.
NodeList movielist = doc.getElementsByTagName("movie");
Element child = (Element)movielist.item(6);
Element newNode = (Element)child.cloneNode(true);
child.appendChild(newNode);
newNode.setAttribute("id", "this is newnode");
code above will clone the whole set of thing. but the problem is it colne in wrong tag. i want some thing like this in my xml file.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<movies>
<movie id="1007">
<title>Interstellar</title>
<genre>Science Fiction</genre>
<duration>180 mins</duration>
</movie>
<movie id="this is newnode">
<title>Interstellar</title>
<genre>Science Fiction</genre>
<duration>180 mins</duration>
</movie>
</movies>
but the code above give me something like this
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<movies>
<movie id="1007">
<title>Interstellar</title>
<genre>Science Fiction</genre>
<duration>180 mins</duration>
<movie id="this is newnode">
<title>Interstellar</title>
<genre>Science Fiction</genre>
<duration>180 mins</duration>
</movie></movie>
</movies>