File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other Open Source Projects and the fly likes Can we create HTML tags using JAVA API ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Can we create HTML tags using JAVA API ?" Watch "Can we create HTML tags using JAVA API ?" New topic

Can we create HTML tags using JAVA API ?

Mohammed Yousuff
Ranch Hand

Joined: Oct 17, 2007
Posts: 198
Is there any API in java which will create HTML tags for me ?

i came accrros some of the HTML parser which will parse the HTML tags. but not sure about the HTML creation.

please let me know if you have any thoughts on this

My Thoughts :
Try not to become a man of success but rather to become a man of value.
Adam Asham

Joined: Jul 06, 2006
Posts: 13
One option could be to utilize the XML DOM package and serialize the created XML nodes. Of course you get no way to detect whether the document is well-formed or not...
[ October 24, 2008: Message edited by: Adam Asham ]
Adam Asham

Joined: Jul 06, 2006
Posts: 13
Hmm, I think javax.swing.text.html is a much better alternative.
I don't know why they put html in there. It's not the most logic location for handling HTML documents...
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63866

There used to be a Jakarta project called ECS (Element Construction Set), but I think it's been long-abandoned.

Of course, if this is in the context of a web app, writing the HTML directly in a JSP is the accepted best practice.

[Asking smart questions] [About Bear] [Books by Bear]
Dan Howard
Ranch Hand

Joined: Feb 22, 2004
Posts: 47
See my thread on Jolene. The document objects that Jolene creates when parsing an HTML file can also be used on their own.


Image img = new Image();
img.setAttribute("src", "/img/smile.png");
img.setAttribute("alt", "Smile");
img.setAfterText("Click me!");

Which would output (using toString):

<button name="MyButton" value="Click"><img alt="Smile" src="/img/smile.png">Click me!</button>
Martijn Verburg

Joined: Jun 24, 2003
Posts: 3275

As an Aside I moved the Jolene thread to the Blatant Advertising forum as per the Javaranch policy, so for those who are interested please check there .

Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Dan Howard
Ranch Hand

Joined: Feb 22, 2004
Posts: 47
This is a small open source project of mine. It's LGPL and I'm not asking for money.

I've been using this approach for building web applications for several years and about 6 months ago I decided to hunker down and put it all together for release. It's a 1% inspiration 99% perspiration thing. It took a lot of work to get it out there and I would like it if some developers would kick the tires a bit.

This is a great forum with a lot of users who I think could benefit from this approach. If you that crass advertising then sorry.
I agree. Here's the link:
subject: Can we create HTML tags using JAVA API ?
jQuery in Action, 3rd edition