Doctype cannot be added after a root element

"Daniel Lévy" <[email protected]>
Newsgroups gmane.comp.java.jdom.general
Message-ID <[email protected]>
Hi,

I want to report through the following example what it seems to me a bug in JDOM 1.1 non considered yet. I found an old report in the archive, but there was no answer. 

Lets have the following stylesheet minimal.xsl:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="xml" doctype-system="minimal.dtd"/>        
<xsl:template match="/">    
    <Minimal/>        
</xsl:template>
</xsl:stylesheet>

Beeing the minimal.dtd:
<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT Minimal EMPTY>

Then if we try to convert this minimal input document:
<?xml version="1.0"?>
<Minimal/>

by means of:
XSLTransformer transformer = new XSLTransformer("minimal.xsl");
			SAXBuilder builder = new SAXBuilder(false);
			Document in = builder.build(new File("minimal.xml"));
			transformer.transform(in);

the following exception will be raised:
"Doctype cannot be added after a root element"

By debugging in the JDOM source, I have attained in the method SAXHandler.startDTD(name,publicID,systemID) the statement factory.addContent(document, factory.docType(name,publicID,systemID)). Now the document parameter contains a dummyroot, added at construction time. The exception is raised because of this dummy root.

I suggest to exclude somehow the dummy root from the check (added in Beta 10).

As a workaround, I have removed the doctype-system attribute from the stylesheet and added the DTD reference in a postprocessing. Any ideas for a workaround without removing the doctype-system attribute?

Regards,
Daniel
-- 
Sensationsangebot verlängert: GMX FreeDSL - Telefonanschluss + DSL 
für nur 16,37 Euro/mtl.!* http://dsl.gmx.de/?ac=OM.AD.PD003K1308T4569a
_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.