wood burning stoves
The moose likes Java in General and the fly likes Validating html tags in a string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Validating html tags in a string" Watch "Validating html tags in a string" New topic

Validating html tags in a string

Chigull Sujatha

Joined: Jan 16, 2003
Posts: 3

I am looking to validate the html tags contained within a string object. Is there any validator/library available so I can just send the string and get a message if the tags are not valid. I have looked at w3cs html validator, but I needed to do something from within my code. Any suggestions. Pls. help!

Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
If you generate the HTML you can make it well-formed XML at the same time. Google for "java xhtml validator" and see what you find.

I think the HTML spec says rendering engines should just ignore anything they don't recognize, so it's "valid" to add your own tags and attributes and such.
How "valid" do you want it to be?

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Purushoth Thambu
Ranch Hand

Joined: May 24, 2003
Posts: 425
If you are hard pressed on detecting any invalid HTML tags then you can make use of HTMLEditorKit API. Take a look at javax.swing.text.html.* package.

This tutorial will help you in getting started on using these API's.

In short the core task will be to override HTMLEditorKit.ParserCallback class's handleError method. I know this question has been asked before in ranch if you search the site you must be able to get further information.
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
The JTidy toolkit is the most highly developed HTML tool that I know of - it may be overkill for your problem.

Chigull Sujatha

Joined: Jan 16, 2003
Posts: 3
Thanks a lot guys, I will checkout the info you all suggested about.

I agree. Here's the link: http://aspose.com/file-tools
subject: Validating html tags in a string
It's not a secret anymore!