I am actually traversing src xml and converting it into another destination xml. But part of src xml will be just copied and added to the destination. But when I am trying to do that I am getting following Exception:
could not be added to the element "<DestinationParent>" because: The Node already has an existing parent of "<SourceParent" I am traversing src XML and calling this function
Code
private static Element treeWalk (Element rootElement, Element parentElement) { Element moduleRootElement = doc.addElement("Request"); if(rootElement.getName()=="someName") { moduleRootElement.add(childElement.getName()); } else { moduleRootElement.add(rootElement); //If root's parent is not null I get a exception here. //moduleRootElement= rootElement.createCopy(); //Didn't work } }