You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xerces.apache.org by Wong Kok Wai <wo...@pacific.net.sg> on 2000/02/24 16:10:03 UTC

Pretty printing of comment nodes

Xerces 1.0.2: Comments nodes are not printed properly by the serializer
IMHO. The following is the patch I've made for
org.apache.xml.serialize.BaseMarkupSerializer:

Index: BaseMarkupSerializer.java
===================================================================
RCS file:
/home/cvspublic/xml-xerces/java/src/org/apache/xml/serialize/BaseMarkupSerializer.java,v

retrieving revision 1.10
diff -r1.10 BaseMarkupSerializer.java
519c519,520
<      indent();
---
>      //indent();
>           breakLine();
521c522,523
<      unindent();
---
>           breakLine();
>      //unindent();

Before the patch, the output file looks like:

<?xml version="1.0" encoding="UTF-8"?>
<root>
    <ele1>
        <ele2 attr1="attrval1"/><!-- This is a comment --></ele1>
</root>


After the patch, the output file looks like:

<?xml version="1.0" encoding="UTF-8"?>
<root>
    <ele1>
        <ele2 attr1="attrval1"/>
        <!-- This is a comment -->
    </ele1>
</root>

However, the bad news is comment that span multiple lines still is
printed on a single line. I couldn't figure out how to fix this.




Re: Pretty printing of comment nodes

Posted by Assaf Arkin <ar...@exoffice.com>.
Wong Kok Wai wrote:
> 
> Xerces 1.0.2: Comments nodes are not printed properly by the serializer
> IMHO. The following is the patch I've made for
> org.apache.xml.serialize.BaseMarkupSerializer:

Not that simple. The serializer will now add a space between the element
and comment, which is good for indentation, but might not belong there.

There's code for dealing with that for XML and specifically for HTML
(some nasty behavior in Netscape 4.7) with regards for text content, so
the comment code should be just as sophisticated.

> However, the bad news is comment that span multiple lines still is
> printed on a single line. I couldn't figure out how to fix this.

Even more complex. My comments are indented manually as I put them in
the text file (and I've seen that happen in several other places).
Making the serializer indent that text requires some extra logic to
remove or deal with the existing indentation.

arkin


-- 
----------------------------------------------------------------------
Assaf Arkin                                           www.exoffice.com
CTO, Exoffice Technologies, Inc.                        www.exolab.org