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>