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

Jason Hunter jhunter at xquery.com
Thu Feb 26 15:21:04 PST 2004


I would rather do (1) and do it in such a way that it (a) didn't depend 
on any particular parser and (b) was more efficient than streaming the 
document out and reparsing.  It's been on the TODO list for a while.  We 
just need someone to want it enough to write it.

-jh-

Rick Beton wrote:

> 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 
> coexist.
> 
> 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?
> 
> Regards,
> Rick :-)
> 
> 



More information about the jdom-interest mailing list