Last active
March 10, 2019 12:21
-
-
Save ezhov-da/4e2b74d1411ebb67b1f72a082728c4b6 to your computer and use it in GitHub Desktop.
java xml transform
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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