0

I'm looking for a Java-library which allows me to validate HTML-Snippets like this:

<div class=something>
    <iframesrc="link">

I have see solutions to validate a whole website or ways to check if tags are written correctly, but not for validations to check for closing-tags.

Has someone an idea for that?

Kind regards

Skolak
  • 21
  • 7
  • I have seen this post. As i understood it, these libs only take whole websites (...). Because i only want to validate a snipped, it is not supported unless i add the missing tags manually every time i want to validate it... and this is a thing i realy want to avoid... – Skolak Jun 29 '20 at 13:25
  • Im not sure i can help you with this but Can you check with Jsoup? – soorapadman Jun 29 '20 at 14:01
  • Yes this is possible. I write it as an answer and a "how to". Thank you. – Skolak Jun 29 '20 at 15:21

1 Answers1

0

Ok, the lib Jsoup works here.

to use it:

String htmlSnippetString = "<div...";
Whitelist whitelist = Whitelist.basic(); //here you define what HTML is allowed
boolean htmlTest = Jsoup.isValid(htmlSnippetString, whitelist);

Thanks to @soorapadman

Skolak
  • 21
  • 7