[jdom-interest] DOCTYPE instruction & JDOMSource

Gernot Koller gernot at kabsi.at
Thu Feb 21 03:47:21 PST 2002

jhunter at acm.org wrote:
> Are you using the latest code in CVS?
Sorry, forgot to tell what version I was using.
Originally I was working with JDOM Beta 7 binary build, but I took the
time and could verify the problem with todays CVS snapshot, too.
This is the code to reproduce the problem:
--------------------- 8< ------------------------------
import java.io.FileOutputStream;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.output.XMLOutputter;
import org.jdom.transform.JDOMResult;
import org.jdom.transform.JDOMSource;
public class jdomtest
public static void main(String[] args)
FileOutputStream out =
new FileOutputStream("output.html");
Transformer transformer =
new StreamSource("stylesheet.xsl"));
Element root = new Element("root");
Document document = new Document(root);
JDOMSource source = new JDOMSource(document);
JDOMResult result = new JDOMResult();
transformer.transform(source, result);
XMLOutputter outputter = new XMLOutputter(" ", true);
outputter.output(result.getDocument(), out);
StreamResult result2 = new StreamResult("output2.html");
transformer.transform(source, result2);
catch (Exception e)
----------------------- 8< -----------------------
using the following stylesheet.xsl
----------------------- 8< -----------------------
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
<xsl:output method="html" encoding="utf-8"
doctype-public="-//W3C//DTD HTML 4.0 Transitional//EN"
doctype-system="http://www.w3.org/TR/REC-html4/loose.dtd" indent="yes"/>
<xsl:template match="/">
<html><h1>Hello World!</h1></html>
----------------------- 8< -----------------------
resulting in two output files which should be equal to my opinion but
differ in the DOCTYPE instruction:
----------------------- 8< -----------------------
<?xml version="1.0" encoding="UTF-8"?>
<h1>Hello World!</h1>
----------------------- 8< -----------------------
----------------------- 8< -----------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
<h1>hello World!</h1>
----------------------- 8< -----------------------


More information about the jdom-interest mailing list