I have the following XML :
<root>
<para>My paragraph with my <photo>MyPhoto</photo>
</para>
</root>
and I want to replace an element <photo>MyPhoto</photo>
by this <name>MyName</name>
I use dom4j in my project :
List myPhotoToRemove = doc.selectNodes("//photo");
for(Object o : myPhotoToRemove){
o = DocumentHelper.createElement("name");
((Element)o).setText("MyName");
}
It creates an element <name>
without parent
Try following
List<Node> myPhotoToRemove = doc.selectNodes("//photo");
for(Node node : myPhotoToRemove){
node.setName("name");
node.setText("MyName");
}