My intention is to edit HTML documents, including modifying existing elements, deleting elements and inserting new ones.
I've read HTMLEditorKit's and related classes' documentation, as well as the relevant topic in Sun's Java Trail, yet there is very little information about actual HTML document manipulation. Most of the discussion and examples deal with reading and parsing HTML, not really editing it. Some Googling still did not yield an adequate solution, and trying to tackle the task with some coding trial and error mostly resulted in exceptions.
I've gone over related questions and answers here in SO, but most answers suggested some alternative, while I'm looking for a solution in the JDK. Perhaps HTMLEditorKit is of little use to non-swing applications, and there is an alternative outside javax.swing?
Here are a few tasks I'd like to learn how to perform:
- Replace text in certain text fields.
- Basic editing (find/replace or
regexes) of
<script>
elements. - Color the border of certain elements.
- Remove certain tags entirely (for example flash elements).
Assuming that HTMLEditorKit is the best HTML editing component in the JDK, what tutorial or reference do you recommend?