File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XML Gurus. Deep cloning a node without using clone(true)

 
Francesco Marchioni
author
Ranch Hand
Posts: 194
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all,
I have to copy one piece of XML from one part of the document to another. Unfortunately I cannot simply do a copy and paste:

Node nodeLeaf = nodeChild.cloneNode(true);
nodeAncestor.appendChild(nodeLeaf);

because some fragments of the nodeLeaf mustn't be copied (depending on the node value)

So I cannot make a deep clone of the leaf.
I have to make a clone of nodeLeaf by myself. (Copying its child with a recursive function)

I have built a recursive function but I cannot understand why it doesn't work correclty (text values are skipped and also some pieces of the xml aren't copied correclty)



Anybody can give me a help ?
thanks a lot
Francesco
 
Rajagopal Manohar
Ranch Hand
Posts: 183
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
text values are skipped and also some pieces of the xml aren't copied correclty



node.getChildNodes();will return only the child nodes (kids ) not descendents (grand children and above).

Text nodes are usually children of element nodes in which they are contained unless they are whitespaces around the element.

See if you can work out a new recursive solution factoring in what I have said
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic