Check out jsoup - it should handle all your necessary tasks in an elegant way.
[change]
Here is a complete working example for each required operation:
// Load and parse the document fragment. File f = new File("myfile.html"); // See also Jsoup
You want things like case sensitivity not to matter for attribute names, but that should be most of what you need.
source share