Need help with javax.xml.transform.Transformer! Urgent!
Hi!
I am currently using javax.xml.transform.Transformer to get XML from ado
Mdo
cument. I have to declare ado
CTYPE either externally or internally in an XML file. I have had some problems with the externaldo
CTYPE because I couldn't specify the base URI (because Ido
n't know where the application will be installed). Therefore, I thought it would be a good idea to specify thedo
CTYPE internally, i.e. by giving the DTD specification with the XML file itself.
When using Transformer, I get a problem. The problem is that the transform() methoddo
esn't write the internaldo
CTYPE declaration to my XML file. An example of the kind of XML file I want to use:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE entries [
<!ELEMENT entries (entry)*>
<!ELEMENT entry (active | line | station | reason)>
<!ELEMENT active (CDATA)>
<!ELEMENT line (CDATA)>
<!ELEMENT station (CDATA)>
<!ELEMENT reason (CDATA)>
]>
<entries>
<entry>
<line>134</line>
<station>332</station>
<reason>The stupid thing is not working</reason>
</entry>
</entries>
Is there a way of configuring the Transformer so that the internaldo
CTYPE declaration is written with the XML data? Alternatively, is there an other way of solving the problem?
My Transformer code is like this:
try { transformer = TransformerFactory.newInstance().newTransformer();
/* * Tried a lot of things with this method without luck... * transformer.setOutputProperty(javax.xml.transform.OutputKeys.?????, dtdDeclaration);
*/} catch (TransformerConfigurationException e) { e.printStackTrace();} catch (TransformerFactoryConfigurationError transformerFactoryConfigurationError) { transformerFactoryConfigurationError.printStackTrace();}// Try to transform to XML and write to specified URItry { transformer.transform(newdo
MSource(doc), new StreamResult(new FileOutputStream(new File(absolutePath))));} catch (TransformerException e) { e.printStackTrace();} catch (FileNotFoundException e) { e.printStackTrace();}
Thanks!!