Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can we create HTML tags using JAVA API ?

 
Mohammed Yousuff
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Adam Asham
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Dan Howard
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See my thread on Jolene. The document objects that Jolene creates when parsing an HTML file can also be used on their own.

example:

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

Which would output (using toString):

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


http://jolene.sourceforge.net/
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 .
 
Dan Howard
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic