I'm trying to serialize a tree that was built using xerces. The point is that 
this tree has many ignorable
whitespaces node in it (basically one every 2 nodes).

When I try to serialize with options setPreserveSpace(false) and 
setIndenting(true), the identation is not
down correctly. Basically, no carriage return is down. After looking at
org.apache.xml.serialize.BaseMarkupSerializer and 
org.apache.xml.serialize.XmlSerializer, it appears that
there are two main problems :
    - the content() method is called in BaseMarkupSerializer for a text node 
and changes the element state
from empty to non empty.
Thus, when the first subelements of an element are an ignorable text node and 
then an element, the state goes
to non empty while the ignorable text node is serialized and the element don't 
print a carriage return since
the state is non empty nor afterElement when it arrives.
    - in the same way content make state.afterElement equal to false. So when 
you got element - ignorable
text node - element, the 2 elements are on the same line

At last, comments are taken for text and thus no carriage return is printed 
before and after them. So if your
xml has comments every 2 lines that explains what the data are, it is 
serialized on a single line...

Sebastien

Reply via email to