One question to your sample code.
- Code: Select all
Paragraph para = (Paragraph) bk.getBookmarkStart().getOwner();
Section sec = (Section) para.getOwner().getOwner();
Will these two lines always work, i.e., will the 1st line always return a Paragraph object and will the 2nd line always return a Section object? Or do I have to check the returned instance type?
Saying that, wouldn't it be more precise to use the following code?
- Code: Select all
Paragraph para = bk.getBookmarkStart().getOwnerParagraph();
bookmarksNavigator.moveToBookmark(bk.getName());
bookmarksNavigator.deleteBookmarkContent(true);
if (para.getText().isEmpty()) {
para.getOwner().getChildObjects().remove(para);
}
Or should I better use this alternative code?
- Code: Select all
Paragraph para = bk.getBookmarkStart().getOwnerParagraph();
bookmarksNavigator.moveToBookmark(bk.getName());
bookmarksNavigator.deleteBookmarkContent(true);
if (para.getText().isEmpty()) {
Section sec = para.getParentSection();
sec.getParagraphs().remove(para);
}
As you can see, I'm looking for a general purpose code that works for any document structure.
Kind regards,
Marcus