Rather than odtDocument.getRootNode(), you could use the paragraphNode here as the root. This would allow iteration to complete sooner if there is no walkable position before the end of the paragraph, as iteration would terminate as soon as the end of the paragraph is reached, rather than the next step *after* the paragraph.

There is no major performance issues with the code as written however, so don't feel you need to change this :)