[jdom-interest] Re: XMLOutputter and Comments
Elliotte Rusty Harold
elharo at metalab.unc.edu
Wed Jun 21 14:04:35 PDT 2000
At 12:22 PM -0700 6/21/00, Jason Hunter wrote:
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?
>
>Can you explain cases where you'd want to do things differently?
>
What I really want to do is this. Instead of
<tag>several thousand characters of text...</tag>
I want to be able to output
<tag>
80 characters of text...
another 80 characters of text...
another 80 characters of text...
...
</tag>
Providing a protected printText() method doesn't seem sufficient for
this purpose since when the method started, the start tag would have
already been written onto the stream and you wouldn't know where you
were on the line. And I'd still like to be able to output
<strong>small amount of text</strong> on one line like this:
<strong>small amount of text</strong>
so the decision about word wrapping (or not) needs to be made in the
printElement() method. However, word wrapping isn't necessary for
empty elements or elements that only contain child elements.
The algorithms for all three element types are different. Right now
they're split by an if-else-if block in printElement() that handles
each of the three cases. I'd prefer to split the three cases into
separate methods dispatched from printElement() so that they could be
overridden or changed separately.
The more I think about this, the trickier it seems. Certainly what
we've got now is good enough for most cases, but it really does miss
the simple case of pretty printing with word wrapping of long lines.
Of course, I suppose you'd probably want to wrap long tag names and
attribute lists too. I wonder if this doesn't require a full-fledged
redesign of the class so that all methods know which column they're
on at any given time. I need to think about this some more.
+-----------------------+------------------------+-------------------+
| Elliotte Rusty Harold | elharo at metalab.unc.edu | Writer/Programmer |
+-----------------------+------------------------+-------------------+
| The XML Bible (IDG Books, 1999) |
| http://metalab.unc.edu/xml/books/bible/ |
| http://www.amazon.com/exec/obidos/ISBN=0764532367/cafeaulaitA/ |
+----------------------------------+---------------------------------+
| Read Cafe au Lait for Java News: http://metalab.unc.edu/javafaq/ |
| Read Cafe con Leche for XML News: http://metalab.unc.edu/xml/ |
+----------------------------------+---------------------------------+
More information about the jdom-interest
mailing list