The Element Construction Set is a Java API for generating elements for various markup languages it directly supports HTML 4.0 and XML, but can easily be extended to create tags for any markup language. It is designed and implemented by Stephan Nagy and Jon S. Stevens.
out.println("<HTML>");
out.println("<HEAD><TITLE>Demo<TITLE><HEAD>");
out.println("<BODY>");
out.println("<H1>Demo Header<H1>");
out.println("<H3>Sub Header:<H3>");
out.println("<FONT SIZE=\"+1\" FACE=\"Times\" COLOR=\"#FFFFFF">The big dog & the little cat chased each other.<FONT>");
out.println("<BODY>");
out.println("<HTML>");
You can do this instead:
Html html = new Html()
.addElement(new Head()
.addElement(new Title("Demo")
.addElement(new Body()
.addElement(new H1("Demo Header"))
.addElement(new H3("Sub Header:"))
.addElement(new Font().setSize("+1")
.setColor(HtmlColor.WHITE)
.setFace("Times")
.addElement("The big dog & the little cat chased each other.));
out.println(html.toString());
// or write to the outputstream directly
output(out);
Or even easier, use the Document object:
Document doc = new Document()
.appendTitle("Demo")
.appendBody(new H1("Demo Header"))
.appendBody(new H3("Sub Header:"))
.appendBody(new Font().setSize("+1")
.setColor(HtmlColor.WHITE)
.setFace("Times")
.addElement("The big dog & the little cat chased each other.));
out.println(doc.toString());
// or write to the outputstream directly
output(out);
There are some subtleties in the above code that are worth commenting on.
XML my_element = new XML("my_element");
produces: <my_element></my_element>
Thanks for your interest in ECS!
Copyright (c) 1999
The Java Apache Project.
$Id: index.html,v 1.1.1.1 1999/04/20 01:18:57 jonbolt Exp $
All rights reserved.