I was reading a book(The Tangled Web) -- what I list below is my understanding of the steps involved in writing a good markup filter.
- build an in-memory document tree - walk the tree - remove unnecessary tags - remove unnecessary parameters/values - reserialize the document - apply escaping to text content and parameter values - do not allow "name" and "id" parameters in user supplied markup
I'm looking for recommendations on robust libraries for parsing HTML, in Java. I'm hoping for suggestions on libraries that have been widely audited/used.
So far I have come across the following :-
- JSoup, http://jsoup.org/
- JTidy, http://jtidy.sourceforge.net/
- A similar SO question, http://stackoverflow.com/questions/238036/java-html-parsing
- Cobra, http://lobobrowser.org/cobra.jsp
- Another list of Java parsers, http://java-source.net/open-source/html-parsers
Because of the large number of parsers that are out there, I'm unsure about which ones to use. My selection criterion would be the robustness of a parser i.e. it should handle malformed input in a defined manner.