M
Michael Preminger
Hello!
I am trying to create an XHTML-document using the org.w3c.dom and
javax.xml.transform package, but cannot find
any elegant way of putting a <DOCTYPE declaration into the output document.
I create a Document object with the newDocument() method of a
javax.xml.parsers.DocumentBuilder object, and writing it out using an
identity transform, (as in sun's tutorial
http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JAXPXSLT4.html)
The turorial has a recommendation for processing DOCTYPE, using the
following code:
....
if (document.getDoctype() != null){
String systemValue = (new
File(document.getDoctype().getSystemId())).getName();
transformer.setOutputProperty(
OutputKeys.DOCTYPE_SYSTEM, systemValue
);
}
But this does not seem to have the effect I expect, and is probably not
intended for my expressed need.
Is there a standard way of setting a
<DOCTYPE ...> declaration to a DOM - document created in this way, or do
I have to create my XHTML some other way?
Thanks
Michael
I am trying to create an XHTML-document using the org.w3c.dom and
javax.xml.transform package, but cannot find
any elegant way of putting a <DOCTYPE declaration into the output document.
I create a Document object with the newDocument() method of a
javax.xml.parsers.DocumentBuilder object, and writing it out using an
identity transform, (as in sun's tutorial
http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JAXPXSLT4.html)
The turorial has a recommendation for processing DOCTYPE, using the
following code:
....
if (document.getDoctype() != null){
String systemValue = (new
File(document.getDoctype().getSystemId())).getName();
transformer.setOutputProperty(
OutputKeys.DOCTYPE_SYSTEM, systemValue
);
}
But this does not seem to have the effect I expect, and is probably not
intended for my expressed need.
Is there a standard way of setting a
<DOCTYPE ...> declaration to a DOM - document created in this way, or do
I have to create my XHTML some other way?
Thanks
Michael