Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Remove <?xml version="1.0" encoding="UTF-8"?> from XML doc

843834Jun 26 2006 — edited Jun 27 2006
I have generated an XML file using javax XML transformer. In the XML file thats generated I have the version and the encoding line

<?xml version="1.0" encoding="UTF-8"?>

which is automatically generated in my XML file. Is there any way that I can avoid that from the XML file thats generated.

Here is the transformer that I have used.
public static void printToXML(String fileName){
		 try{
			 File file = new File(fileName);
			 Transformer tr = TransformerFactory.newInstance().newTransformer();
			 tr.setOutputProperty(OutputKeys.INDENT, "yes");
			 tr.setOutputProperty(OutputKeys.METHOD,"xml");
			 tr.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "3");
			 tr.transform( new DOMSource(dom),new StreamResult(new FileWriter(file)));
		 }catch(TransformerConfigurationException tcex){
			 logger.info("TransformerConfigurationException at printToXML method in CSVtoXML.java");
			 logger.error("TransformerConfigurationException", tcex);
		 }catch(TransformerException tex){
			 logger.info("TransformerException at printToXML method in CSVtoXML.java");
			 logger.error("TransformerException", tex);
		 }catch(IOException ioex){
			 logger.info("IOException at printToXML method in CSVtoXML.java");
			 logger.error("IOException", ioex);
		 }
	 }
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 25 2006
Added on Jun 26 2006
2 comments
544 views