I'm generating XML file by taking XML/HTML file (temp.xml) and XSLT(temp.xsl) as input and my output is generated as a separate file with the new name(temp_copy.xml) but I want to overwrite the input XML file instead of creating a new file. I tried by giving the same path as it was in the input file but that didn't work. So what can be the other way to achieve this? Thanks in advance.
My Java code:
public class SimpleXSLT {
public static void main(String[] args) {
String inXML = "C:/tmp/temp.xml";
String inXSL = "C:/tmp/temp.xsl";
String outTXT = "C:/tmp/temp_copy.xml";
SimpleXSLT st = new SimpleXSLT();
try {
st.transform(inXML,inXSL,outTXT);
} catch(TransformerConfigurationException e) {
System.err.println("Invalid factory configuration");
System.err.println(e);
} catch(TransformerException e) {
System.err.println("Error during transformation");
System.err.println(e);
}
}
public void transform(String inXML,String inXSL,String outTXT)
throws TransformerConfigurationException,
TransformerException {
TransformerFactory factory = TransformerFactory.newInstance();
StreamSource xslStream = new StreamSource(inXSL);
Transformer transformer = factory.newTransformer(xslStream);
transformer.setErrorListener(new MyErrorListener());
StreamSource in = new StreamSource(inXML);
StreamResult out = new StreamResult(outTXT);
transformer.transform(in,out);
System.out.println("The generated XML file is:" + outTXT);
}
}