[jdom-interest] generating html content with jdom

guru at stinky.com guru at stinky.com
Fri Jun 29 11:50:42 PDT 2001

> > > *  what's the best way to send a space character? I mean, there's a
> table
> > > cell (<td>) that's supposed to be empty. With "standard" html I'd use
> > > "<td>&nbsp;</td>".  Currently what I have is this:
> > >  new Element("td").addContent(new EntityRef("#160"));
> > > Is this the right solution?
> > I'd think new EntityRef("nbsp") would work fine.
> As far as I remember from the XML specs, nbsp is not a built-in entity. I
> can only use it if I declare the DOCTYPE as the xhtml DOCTYPE.

Only if you care about DTDs.  Or I guess SAX parsers try to expand
entities by default.  But the following Java code generates a
perfectly outputtable JDOM document. 

	Document d = new Document( new Element("p").addContent
			   (new EntityRef("nbsp")));

And it probably will continue to work, since Jason has opined against
validate-on-insert semantics.

Sure, other XML parsers may complain, but not web browsers.

Alex Chaffee                       mailto:alex at jguru.com
jGuru - Java News and FAQs         http://www.jguru.com/alex/
Creator of Gamelan                 http://www.gamelan.com/
Founder of Purple Technology       http://www.purpletech.com/
Curator of Stinky Art Collective   http://www.stinky.com/

More information about the jdom-interest mailing list