You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by "KLOSE, Norbert" <Kl...@ser.com> on 2000/10/23 11:55:11 UTC

org.apache.xml.serialze.Printer.java bug ...

Hi all,

there's a bug in org.apache.xml.serialze.Printer.java: because
flushLine(boolean preserveSpace) is not implemented in Xerces-J 1.2.0 (same
in the snapshot from Oct. 23, 2000) DTD with an internal subset are not
serialized as expected:

This is a *very* simple exsample:

import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.apache.xml.serialize.*;

public class test_serialize {

    public static void main(String[] args) {
        try {
            javax.xml.parsers.DocumentBuilderFactory factory =
                javax.xml.parsers.DocumentBuilderFactory.newInstance();
            factory.setNamespaceAware(true);
            factory.setValidating(false);
            javax.xml.parsers.DocumentBuilder parser =
                factory.newDocumentBuilder();
            Document doc = parser.parse(args[0]);
            OutputFormat format = new OutputFormat(doc);
            XMLSerializer serializer = new XMLSerializer(System.out,
format);
            format.setOmitXMLDeclaration(false);
            format.setOmitDocumentType(false);
            serializer.serialize(doc);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

If you invoke test_serialize on an input like:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE greeting [
<!ELEMENT greeting (#PCDATA)>
]>
<greeting>Hello World!</greeting>

you will receive the following output:

<!ELEMENT greeting (#PCDATA)>
<?xml version="1.0" encoding="UTF-8"?>
<greeting>Hello World!</greeting>

with a starting blank line and no <!DOCTYPE [...]>. This is because in
BaseMarkupSerializer.serializeNode(Node node) the internal subset is printed
with Printer.printText(internal), but the Printer only buffers this text.
When leaveDTD() is called from XMLSerialize.startDocument, this will call
Printer.leaveDTD(), which calls flushLine(false) and switches from the
_dtdwriter to the _docwriter. But Printer.flushLine is not implemented (yet?
// NOOP), so that leaveDTD does not return the content from the buffer.
Implementing flushLine throught a call Printer.flush works fine, but is not
done yet!

Mit freundlichen Grüßen / Kind Regards,

Dipl.-Inform. Norbert Klose
SER Systems AG
Geschäftsstelle Frankfurt, Document Management Systems
Solmsstraße 2-22, D-60486 Frankfurt am Main, Germany
Office: +49 (069) 70768505, Mobile: +49 (0172) 6651482