Details
-
Type:
Improvement
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: 1.5.1
-
Fix Version/s: 1.6-rc-1, 1.5.8, 1.7-beta-1
-
Component/s: None
-
Labels:None
-
Testcase included:yes
-
Number of attachments :
Description
I haven't found docs about removing groovy.util.Node but this seems kind of wrong. I can remove a node but the parent of this node is still the old parent.
def xml = '''
<foo>
<bar id="1" />
<bar id="2" />
<bar id="3" />
</foo>'''
Node foo = new XmlParser().parseText(xml)
assert foo.bar.size() == 3
Node bar2 = foo.bar.find {it.@id == '2'}
bar2.parent().children().remove(bar2)
assert foo.bar.size() == 2
assert ! foo.bar.contains(bar2)
assert bar2.parent() == null // this fails
I looked a bit deeper and found that the parent properties is never updated. I.e. if loading nodes from tree a and inserting them into some children list of tree b doesn't work either. I would have thought that this would be done via a nodelist class. Does this mean that Node trees are basically meant read only?