Transforming DOM Node to HTML with JAXP
import java.io.File;
import java.io.FileOutputStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
public class MainClass {
public static void main(String args[]) throws Exception {
TransformerFactory factory = TransformerFactory.newInstance();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
DOMSource stylesheet = new DOMSource(db.parse(new File("y.xml")));
StreamSource xmlDoc = new StreamSource(args[0]);
StreamResult result = new StreamResult(new FileOutputStream(args[2]));
Transformer transFormer = factory.newTransformer(stylesheet);
transFormer.transform(xmlDoc, result);
}
}
Related examples in the same category