It's fairly risky trying to manipulate HTML as a String that way. HTML is often badly formed and you might pick up stray < and > characters in the text.
The HTMLEditorKit in the library has an HTML parser. You can Google for other parsers, too. I used to use an older version of the Quiotix parser. Parsers might have trouble with your small fragments if they're looking for html and body tags and such, or they might work just fine.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi