我实际上是在遍历src
xml 并将其转换为另一个destination
xml。但是部分src
xml 将被复制并添加到destination
. 但是当我试图这样做时,我得到了以下异常:
could not be added to the element "<DestinationParent>" because: The Node already has an existing parent of "<SourceParent"
我正在遍历 src XML 并调用此函数
代码
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
}
}