I mentioned this issue in the xalan list.
See http://www.nabble.com/Fomatting-question-serializing-DOM-with- pretty-print-tf3252607.html

If you don't want to use the deprecated xerces serializer you can filter out the whitespace first. This filter was already mentioned in the forum which can be set on the serializer: static LSSerializerFilter skipWhitespaceFilter = new LSSerializerFilter()
        {
                public short acceptNode(Node n)
                {
                        if (n.getNodeType() == Node.TEXT_NODE)
                        {
                                return (n.getNodeValue().trim().length() == 0) 
? FILTER_REJECT
                                                : FILTER_ACCEPT;
                        }
                        return FILTER_ACCEPT;
                }

                public int getWhatToShow()
                {
                        return NodeFilter.SHOW_ALL;
                }

                public short startElement(Element elem)
                {
                        return FILTER_ACCEPT;
                }
        };

You may want this filter more precise by filtering out only the whitespace in mixed content nodes.

Regards
Dick Deneer


Op 5-apr-2007, om 19:04 heeft Rafał Gierusz het volgende geschreven:

I'm using Xerces 2.9.0. any idea about this version and my problem?
Should I use other mailing list (xalan)?

Michael Glavassevich wrote:
You haven't said what release you tried this with (assuming it's Xerces). Note that "format-pretty-print" has only been implemented since Xerces 2.8.0. If you're using Xerces 2.9.0 the LSSerializer is based on Xalan
which has different behaviour with respect to pretty-printing.

Rafał Gierusz <[EMAIL PROTECTED]> wrote on 04/05/2007 05:39:51 AM:

Hello,

I would like to make "pretty-print" xml using LSSerializer, so a write:

LSSerializer serializer = ...
serializer.getDomConfig().setParameter("format-pretty-print", true);

then I get string with "pretty-print" xml using metod:
serializer.writeToString(... DOMDocument ...));

and the result is:

<a xmlns:z="http://a.com";>
   <b>
      <z:c/>



                      </b>
</a>

whitespaces inside "<b>" tag are not removed (after "<z:c/>" tag). Does
anyone know how to remove this whitespaces?


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Reply via email to