Transformation code in java
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
public class XMLTransform {
public static void main(String args[]) {
// if (args.length != 1) {
// System.err.println("Usage: java XMLTransform xmlfile.xml");
// System.exit(-1);
// }
try {
StreamSource source = new StreamSource(args[0]);
StreamSource stylesource = new StreamSource("t1.xsl");
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(stylesource);
StreamResult result = new StreamResult(System.out);
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.transform(source, result);
} catch (Exception e) {
e.printStackTrace();
}
}
}
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
public class XMLTransform {
public static void main(String args[]) {
// if (args.length != 1) {
// System.err.println("Usage: java XMLTransform xmlfile.xml");
// System.exit(-1);
// }
try {
StreamSource source = new StreamSource(args[0]);
StreamSource stylesource = new StreamSource("t1.xsl");
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(stylesource);
StreamResult result = new StreamResult(System.out);
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.transform(source, result);
} catch (Exception e) {
e.printStackTrace();
}
}
}
0 Comments:
Post a Comment
<< Home