Skip to content

Instantly share code, notes, and snippets.

@ezhov-da
Last active March 10, 2019 12:21
Show Gist options
  • Save ezhov-da/4e2b74d1411ebb67b1f72a082728c4b6 to your computer and use it in GitHub Desktop.
Save ezhov-da/4e2b74d1411ebb67b1f72a082728c4b6 to your computer and use it in GitHub Desktop.
java xml transform
[code:]java[:code]
package ru.ezhov.xml;
import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;
/**
*
* @author ezhov_da
*/
public class App
{
private static final Logger LOG = Logger.getLogger(App.class.getName());
public static void main(String[] args) throws TransformerConfigurationException
{
// Car car = new Car(4, 4);
// JAXB.marshal(car, file);
File stylesheet = new File("car.xsl");
File datafile = new File("car.xml");
File outfile = new File("out_car.xml");
try
{
TransformerFactory factory = TransformerFactory.newInstance();
Source xslt = new StreamSource(stylesheet);
Transformer transformer = factory.newTransformer(xslt);
Source text = new StreamSource(datafile);
transformer.transform(text, new StreamResult(outfile));
} catch (TransformerException ex)
{
Logger.getLogger(App.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
[/code]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment