[jdom-interest] Re: XMLOutputter and Comments

Elliotte Rusty Harold elharo at metalab.unc.edu
Wed Jun 21 14:02:13 PDT 2000


I've revised XMLOutputter to add these three methods:

protected void printComment(Comment comment, Writer out, int
indentLevel)  throws IOException 
protected void printEntity(Entity entity, Writer out) throws IOException 
protected void printProcessingInstruction(ProcessingInstruction pi,
Writer out, int indentLevel) throws IOException 

I also deleted

protected void printProcessingInstructions(List pis, Writer out) throws
IOException 

and revised printElement() and printDocument() to use these new methods.
This makes XMLOutputter a lot easier for subclasses to customize. Along
the way, I also made the newline printing more consistent so that you no
longer get those annoying extra blank lines in the prolog. I've tested
the changes against all the examples I had easily available and they
seem to work. 

The code is at http://metalab.unc.edu/xml/jdom/XMLOutputter.java

I'm also thinking about adding this method: 

protected void printText(String text, Writer out, int indentLevel)
throws IOException 

Overriding it would allow subclasses to customize how text is arranged;
for example, allowing them to turn word wrapping on or off. The problem
is this might require different algorithms depending on whether or not
the text was part of mixed or string only content.  For mixed content
it's fairly straight-forward, but for string only content you'd want to
be able to affect the wrapping of the start and end tags too. Maybe
what's really needed is separate protected methods to handle empty
elements, string only elements, and mixed content elements which
printElement() would call. For example:

protected void printMixedContentElement(Element element, Writer out, int
indentLevel) throws IOException 
protected void printStringOnlyElement(Element element, Writer out, int
indentLevel) throws IOException 
protected void printEmptyElement(Element element, Writer out, int
indentLevel) throws IOException 

Thoughts?



More information about the jdom-interest mailing list