[ 
https://issues.apache.org/jira/browse/GROOVY-5682?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17389040#comment-17389040
 ] 

Pablo Pazos commented on GROOVY-5682:
-------------------------------------

[~paulk] I'm running into this issue. My case is generating alternative XML 
structures for testing a system. The process is:
 # provided a sample XML
 # there is a generatedor that uses XmlParser to parse the sample and traverse 
the nodes
 # when if finds a specific node, it generates different values for it's 
children
 # each generated value does a clone of the original xml
 # then on the clone, the generated values are inserted and the cloned xml is 
saved in an array to be serialized later

The issue is in 5 I need to execute replaceNode, and for the node I have, from 
the cloned structure, I get "can't replace the root element", of course the 
issue is the current node doesn't have the parent set because it was cloned.

 

I don't have a workaround in terms of using the replaceNode{} though I can 
start setting parents by hand, is not a good solution for something that I 
think should come out the clone() method without my intervention.

Now I'm testing the methods submitted by Manish as an alternative to the native 
clone() method.

> Add clone or copy constructor to XML Node
> -----------------------------------------
>
>                 Key: GROOVY-5682
>                 URL: https://issues.apache.org/jira/browse/GROOVY-5682
>             Project: Groovy
>          Issue Type: New Feature
>    Affects Versions: 2.0.1
>            Reporter: Marcel Szalbach
>            Assignee: Paul King
>            Priority: Minor
>             Fix For: 2.0.2, 2.1.0-beta-1
>
>
> When retrieving an node from an XML there is no easy way to clone this node 
> for further processing without changing the original XML.
> Currently I used a workaround:
> {code:java}
> def clonedNode = new XmlParser().parseText( XmlUtil.serialize( xmlNode ) )
> {code}
> It would be a lot easier if the Node object have a copy constructor or clone 
> would be supported.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to