[jdom-interest] Beta-10 DocType cannot be added after root?
Jason Hunter
jhunter at xquery.com
Wed Jul 7 10:53:18 PDT 2004
Yes, we now enforce that doctypes must come before the root element.
-jh-
Gary Lawrence Murphy wrote:
> This code worked fine with Beta 9, but under Beta 10, it throws an
> exception calling javax.xml.transform.Transformer.transform():
>
> JDOMSource jds = new JDOMSource(dom);
> jds.getXMLReader()
> .setFeature("http://xml.org/sax/features/validation",
> false);
>
> JDOMResult newdom = new JDOMResult();
>
> Transformer xslt = tfact.newTransformer(new StreamSource(xsl));
>
> xslt.setOutputProperty(OutputKeys.STANDALONE, "yes");
> xslt.setOutputProperty(OutputKeys.METHOD, "xml");
> xslt.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
> xslt.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC,
> getConfig()
> .getString(SML_PUBLIC_PROPERTY,
> SML_PUBLIC_DEFAULT));
>
> xslt.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,
> newdtd.getSystemID());
>
> xslt.transform( jds, newdom);
>
> this throws the following exception and traces back to that last statement:
>
> org.jdom.IllegalAddException: A DocType cannot be added after the root element
> at org.jdom.Document.canContain(Document.java:712)
> at org.jdom.ContentList.add(ContentList.java:146)
> at org.jdom.ContentList.add(ContentList.java:127)
> at java.util.AbstractList.add(AbstractList.java:88)
> at org.jdom.Document.addContent(Document.java:317)
> at org.jdom.input.SAXHandler.startDTD(SAXHandler.java:705)
> at org.jdom.transform.JDOMResult$DocumentBuilder.startDTD(JDOMResult.ja\va:586)
> at org.apache.xml.serializer.ToXMLSAXHandler.startElement(ToXMLSAXHandl\er.java:697)
> at org.apache.xml.serializer.ToXMLSAXHandler.startElement(ToXMLSAXHandl\er.java:541)
> at org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResu\lt.java:661)
> at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(T\ransformerImpl.java:2362)
> at org.apache.xalan.transformer.TransformerImpl.applyTemplateToNode(Tra\nsformerImpl.java:2228)
> at org.apache.xalan.transformer.TransformerImpl.transformNode(Transform\erImpl.java:1306)
> at org.apache.xalan.transformer.TransformerImpl.transform(TransformerIm\pl.java:704)
> at org.apache.xalan.transformer.TransformerImpl.transform(TransformerIm\pl.java:1222)
> at org.apache.xalan.transformer.TransformerImpl.transform(TransformerIm\pl.java:1200)
> at ca.cbc.sportwire.dochandler.ToNewsMLFilter.processDocument(ToNewsMLF\ilter.java:308)
>
> /Curiously/, a bit farther down in the source, I /do/ attempt to replace
> the DocType with this ...
>
> newdom.getDocument().setDocType(newdtd);
>
> but the exception clearly happens in a try/catch block long before this
> line.
>
> Is there something new/fixed between b9 and b10 that I'm missing here?
>
>
More information about the jdom-interest
mailing list