DocumentType to OutputStream -- DocumentType is Lost

I am trying to do the following...

DocumentBuilder builder = DocumentBuilderFactory().newDocumentBuilder();

DOMImplementation domImpl = builder.getDOMImplementation();

DocumentType type = domImpl.createDocumentType("XXX", null, "My.DTD");

Document doc = domImpl.createDocument(null, "XXX", type);

I then try to do a transform:

DOMSource source = new DOMSource(doc);

StreamResult printResult = new StreamResult(System.out);

synchronized(transFactory)

{

transFactory.newTransformer().transform(source, printResult);

}

_

The result of this is that I do not see the <!DOCTYPE blah blah blah> part on the screen. I only see the rest of the document.

PLEASE HELP!!!!!!!

[782 byte] By [markcoth] at [2007-9-26 3:50:56]
# 1

You don't show if you're referencing an actual XSL file for the transformation. If you do, it needs to have a doctype-system or a doctype-public (or both) attribute in the output element.

E.g.:

<xsl:output doctype-system="My.DTD"/>

will generate:

<!DOCTYPE yourRootElementGoesHere SYSTEM "My.DTD">

If you're not using and actual XSL file and rely on the Built-in Template Rules you have to make an XSL file containing a similar line, because this is not part of these rules.

For more information look for the headline "Document type declaration" on this page:

http://www.ibiblio.org/xml/books/bible2/chapters/ch17.html#d1e9432

lk555 at 2007-6-29 12:36:50 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...