Replace range between bookmarks with another range

Hi, @alexey.noskov. I want the demo too. I need to replace from a range(from NodeA to NodeB) marked by bookmarkAB to an another range(from NodeC to NodeD) marked by bookmarkCD.

The range includes any type of nodes.

@Doraemon The code from the referenced topic is quite obsolete and currently there is a built-in method for inserting one document into another. Please see DocumentBuilder.insertDocument or DocumentBuilder.insertDocumentInline method.

In your case you can set text of bookmarkAB to empty string to remove old content, then use the code provided here to extract content of bookmarkCD into separate document. Then you can use DocumentBuilder.moveToBookmark method to move cursor to the bookmark and insert the extracted document.

@alexey.noskov
Thank you for your quick and greatful support. I will try it.

1 Like