]>
Telecom or ♯ on an upswing
我用doc生成.xml遇到麻┭僵ol我呢,
@些c不知道如何加M去的
]>
@些我已可以了
Telecom or ♯ on an upswing
Need help with javax.xml.transform.Transformer! Urgent!
Hi!
I am currently using javax.xml.transform.Transformer to get XML from a DOM Document. I have to declare a DOCTYPE either externally or internally in an XML file. I have had some problems with the external DOCTYPE because I couldn't specify the base URI (because I don't know where the application will be installed). Therefore, I thought it would be a good idea to specify the DOCTYPE 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() method doesn't write the internal DOCTYPE declaration to my XML file. An example of the kind of XML file I want to use:
]>
Is there a way of configuring the Transformer so that the internal DOCTYPE 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(new DOMSource(doc), new StreamResult(new FileOutputStream(new File(absolutePath))));} catch (TransformerException e) { e.printStackTrace();} catch (FileNotFoundException e) { e.printStackTrace();}
Thanks!!