This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Validating html tags in a string" Watch "Validating html tags in a string" New topic
Author

Validating html tags in a string

Chigull Sujatha
Greenhorn

Joined: Jan 16, 2003
Posts: 3
Hi,

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!

Thanks,
Sujatha
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.
http://www.samspublishing.com/articles/article.asp?p=31059&rl=1

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
Rancher

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

Bill
Chigull Sujatha
Greenhorn

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

Sujatha
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Validating html tags in a string
 
Similar Threads
sending back a URL
Need XHTML validator.
Using Javascript in Struts
Action class not being called after validation
validation problem in ActionClass-validation.xml