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.