1

I am trying to validate a String of HTML code. That is, when HTML code syntax is wrong I want to know, perhaps in the form of a return false.

I am currently using JTidy but it doesn't tell me there was bad syntax it just corrects it. I don't need to correct it just say if the synthax is bad or good.

JTidy code:

String s = "<td>cookie<td>";  // bad syntax.
Tidy tidy = new Tidy();

InputStream stream = new ByteArrayInputStream(s.getBytes(StandardCharsets.UTF_8));
tidy.parse(stream, System.out);

Any help is appriciated.

Mike John
  • 818
  • 4
  • 11
  • 29
  • Why is `cookie` bad syntax? – Alohci Jun 17 '14 at 06:51
  • As far as I know `cookie` is the correct way because of the terminating `/` – Mike John Jun 17 '14 at 06:54
  • The closing `` tag is optional in HTML, so `cookie`, in the right context, means two table cells, and is not invalid. – Alohci Jun 17 '14 at 06:58
  • JTidy marks things like that as warnings. Should I just dismiss them? For example I keep getting `` should be ``. If you could show me what an error would look like I woul deeply appriciate it! – Mike John Jun 17 '14 at 07:11

1 Answers1

0

java has inbuilt DOM Parser in it. Use DOM Parser to check. It will also show errors.

swapnil gandhi
  • 816
  • 1
  • 20
  • 38