Doctype cannot be added after a root element

View: New views
2 Messages — Rating Filter:   Alert me  

Doctype cannot be added after a root element

by "Daniel Lévy" :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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/youraddr@...

Parent Message unknown RE: Doctype cannot be added after a root element

by Michael Kay :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> Mickael, is there a reason why Saxon does not notify the DTD
> through SAXResult?

Saxon ignores xsl:output entirely unless it is serializing the result tree;
and writing to a SAXResult does not count as serializing.

(There are various other aspects of xsl:output that MIGHT make sense with a
SAXResult, for example indent="yes" and cdata-section-elements. It's never
really occurred to me that anyone would expect this to happen. I've
certainly never seen a spec that suggests it should.)

Michael Kay
http://www.saxonica.com/

_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/youraddr@...