import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.w3c.dom.Document;
public class JAXPTransformNode {
public static void main(String args[]) throws Exception, TransformerException,
FileNotFoundException {
TransformerFactory factory = TransformerFactory.newInstance();
DOMSource stylesheet = new DOMSource(buildDoc(args[1]));
StreamSource xmlDoc = new StreamSource(args[0]);
StreamResult result = new StreamResult(new FileOutputStream(args[2]));
Transformer transFormer = factory.newTransformer(stylesheet);
transFormer.transform(xmlDoc, result);
}
public static Document buildDoc(String document) throws Exception {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document theDocument = db.parse(new File(document));
return theDocument;
}
}
|