How to set Document Type Declaration of xml Document?

Hi,I am referring to "org.w3c.dom.Document".How can we set the Document Type Declaration (DTD) of a document?Thanks.
[144 byte] By [gsoapa] at [2007-11-27 5:45:09]
# 1
You can't. And I don't see any reason to do that. By the time you create that Document, it has already been parsed. The org.w3c.dom methods don't have any facility for validating a Document's contents, that is what the parser is supposed to do.
DrClapa at 2007-7-12 15:26:38 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

Hi,

But when we have to create a document(org.w3c.dom.Document) dynamically, and that document has to be validated against a DTD......How can we do it?

I am using the following code

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

DocumentBuilder builder = factory.newDocumentBuilder();

DOMImplementation domi = builder.getDOMImplementation();

DocumentType docType = domi.createDocumentType("query", null, "c:\\queryDtd.dtd");

Document doc = domi.createDocument(null, "query", docType);

But this code is not working. Resulting document is not having <!DOCTYPE...> tag

I have to build a Doument object (not xml file) whose content is as below

<?xml version='1.0' encoding='utf-8'?>

<!DOCTYPE query SYSTEM "queryDtd.dtd">

<query id="abc123">

<data-source-name>EmployeeDB</data-source-name>

<fields>

<field>id</field>

<field>name</field>

<field>salary</field>

<field>joindate</field>

</fields>

<fetch-limit>10</fetch-limit>

</query>

SubbaRaoa at 2007-7-12 15:26:38 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3
Set the DOCTYPE in the Transformer.TransformerFactory tFactory = TransformerFactory.newInstance();Transformer transformer = tFactory.newTransformer();transformer.setOutputProperty(javax.xml.transform.OutputKeys.DOCTYPE_SYSTEM, "queryDtd.dtd");
dvohra09a at 2007-7-12 15:26:38 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...