[jdom-interest] An easy way to write valid XHTML/SVG (etc) documents

Rick Beton richard.beton at dsl.pipex.com
Thu Feb 26 15:14:15 PST 2004

Hi All,

I'm interested in programmatically generating XML documents for XHTML 
and SVG. I'm not interested in old HTML tag soup any more: I want 
well-formed valid XML documents.  JDOM seems the most suitable tool for 
doing this.

As far as I can tell, JDOM doesn't include a validator. It is very 
effective at creating new well-formed documents, but they might not be 
valid.  There are two possible solutions to this: (1) provide a means to 
use an external validator (e.g. Xerces2) so that an in-memory document 
can be validated; (2) provide a means to produce valid documents by 
construction.  Both approaches would have their merits and both might 

I'm not the person to comment on (1) because I'm new to using JDOM.

On (2), I think there could be sope for adding a small number of classes 
to JDOM, most likely in their own package. Just thinking aloud, how 
about the following three classes?:

    * ValidDocument: an abstract class that knows the DTD based on a 
table-driven set of rules.  This would probably extend Document, but 
alternatively might use a 'decorator' pattern to wrap a Document 
instance (not much use without a common interface though).

    * XHTMLDocument: a concrete subclass that allows elements and 
attributes to be added provided they form a valid XHTML  document. 
Different flavours would be needed to support XHTML 1.0 
Strict/Transitional plus XHTML 1.1 etc.; this wouldn't necessarily need 
another publicly visible class for each flavour: rather, a factory 
method could create suitable (private) subclass instances.

    * SVGDocument: ditto for SVG.

Is this a good idea? Is it worth me putting in a bit of effort to write 
a prototype?

Rick :-)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3455 bytes
Desc: S/MIME Cryptographic Signature
Url : http://jdom.org/pipermail/jdom-interest/attachments/20040226/be5416c6/smime.bin

More information about the jdom-interest mailing list