Mike,

I couldn't reproduce your problem with a simple junit test:

public void testAddCloneToOtherElement() {
DocumentFactory factory = DocumentFactory.getInstance();
Document doc = factory.createDocument();
Element root = doc.addElement("root");
Element parent1 = root.addElement("parent");
Element child1 = parent1.addElement("child");
Element parent2 = (Element) parent1.clone();
root.add(parent2);


assertSame("parent not correct", root, parent2.getParent());
assertSame("document not correct", doc, parent2.getDocument());
Element child2 = parent2.element("child");
assertNotSame("child not cloned", child1, child2);
assertSame("parent not correct", parent2, child2.getParent());
assertSame("document not correct", doc, child2.getDocument());
}


Could you tell me what you are doing different and if possible, could you change the junit test so that it fails?

thanks,
Maarten

Mike Summers wrote:

I have a dom4j program that adds cloned nodes into a Document.

I'm noticing that when it comes time to process the cloned node (this can
include cloning the clone) (I use a recursive treewalk) that the clone is
always missing a Document, and frequently a Parent. This only happens when I
process a clone.

*Roughly*, the scheme is:

private void processNode(Node node){
  clone = node.clone();  //createCopy has the same effect
  try{
    findYourParentXPath.selectSingleNode(node).add(clone);
  }catch(NullPointerException npe){
    node.getParent().add(clone);
  }
  treewalk(clone);
}

with treewalk eventually calling back into processNode.

Dumping the Document I get the mis-processed clones, although in the wrong
location (the search for their parent fails due to the null Document).

Is this out-of-scope for dom4j or am I missing some step? It's almost like the
tree needs to be re-read before processing the clone (not an option in this
case).

If someone has an example of cloning a clone and inserting it into the Document
I'd appreciate a look.

Thanks-- Mike


------------------------------------------------------- This SF.Net email is sponsored by: Sybase ASE Linux Express Edition - download now for FREE LinuxWorld Reader's Choice Award Winner for best database on Linux. http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click _______________________________________________ dom4j-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/dom4j-user







-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE
LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click
_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to