'Replace contents between headings

So what I am trying to do is I want to fetch Heading wise data from word via docx4j and want to replace the data that is in those Headings, I do not want to change the heading text just want to remove all the things in that Heading and replace it with another. I searched everywhere for 4 days but not able to find a successful way of doing it, I can do it by fetching text line by line manually but that won't be efficient so is there any way I can directly get Heading wise data and thn can remove every child in that Heading and append another child in that same heading?

Below I have attached an image of the word document, so thing is I want to remove everything in the Heading1 i.e. "2. Functional Requirements" but I do not want to change the heading or it's heirarchy, I just want to remove everything i.e. 2.1.1 and it's subdata, 2.1, BR_1,etc and want to append data same way here as child of "2. Functional Requirements" Style - Heading1. Below is the image of the word document:

enter image description here

Please Help me, any help is highly appreciated. Thank you, have a great day.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source