Example usage for javax.xml.transform.stream StreamSource StreamSource

List of usage examples for javax.xml.transform.stream StreamSource StreamSource

Introduction

In this page you can find the example usage for javax.xml.transform.stream StreamSource StreamSource.

Prototype

public StreamSource(File f) 

Source Link

Document

Construct a StreamSource from a File.

Usage

From source file:JAXPTransform.java

public static void main(String args[])
        throws TransformerConfigurationException, TransformerException, FileNotFoundException {

    TransformerFactory factory = TransformerFactory.newInstance();

    StreamSource stylesheet = new StreamSource(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);

}

From source file:Main.java

public static void main(String[] args) throws JAXBException {
    JAXBContext jc = JAXBContext.newInstance(Home.class, Person.class, Animal.class);

    Unmarshaller unmarshaller = jc.createUnmarshaller();
    StreamSource xml = new StreamSource("input.xml");
    Home home = unmarshaller.unmarshal(xml, Home.class).getValue();

    for (Object object : home.any) {
        System.out.println(object.getClass());
    }//w  w  w . java 2s .c o m
}

From source file:MainClass.java

public static void main(String argv[]) throws Exception {
    Properties props = System.getProperties();
    props.put("javax.xml.transform.TransformerFactory", "org.apache.xalan.xsltc.trax.TransformerFactoryImpl");
    System.setProperties(props);/*  www .  j  a v a 2s  .  c o  m*/
    TransformerFactory tFactory = TransformerFactory.newInstance();
    Templates translet = tFactory.newTemplates(new StreamSource("OrderProcessing.xslt"));

    Transformer transformer = translet.newTransformer();

    transformer.transform(new StreamSource("CustomerOrders.xml"),
            new StreamResult(new FileOutputStream("SortedOrders.html")));

    transformer.transform(new StreamSource("CustomerOrders1.xml"),
            new StreamResult(new FileOutputStream("SortedOrders1.html")));

}

From source file:XMLTransform.java

public static void main(String[] args) throws Exception {
    System.setProperty("javax.xml.transform.TransformerFactory", "net.sf.saxon.TransformerFactoryImpl");
    SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
    XMLReader reader = parser.getXMLReader();
    TransformerFactory factory = TransformerFactory.newInstance();
    System.out.println(factory);/*from w  w  w .j a v a2 s .c  om*/
    Transformer transformer = factory.newTransformer(new StreamSource("./xsl/books-sql.xsl"));
    transformer.setParameter("user", "root");
    transformer.setParameter("password", "123456");
    transformer.transform(new StreamSource("./xml/books.xml"), new StreamResult(System.out));
}

From source file:JAXPTransformNode.java

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);

}

From source file:MisspelledPersonUnmarshaller.java

public static void main(String[] args) throws JAXBException {
    JAXBContext context = JAXBContext.newInstance("person");
    Unmarshaller unmarshaller = context.createUnmarshaller();

    JAXBElement<Person> element = unmarshaller.unmarshal(new StreamSource("p.xml"), Person.class);
    Person person = element.getValue();// w  w  w.j  a v  a  2 s  .c  o m
    System.out.println(person.getFirstName());

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    URL webSvcGetURL = new URL("http://www.server.net/Webservices");
    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(webSvcGetURL.openStream()));
    SAXSource saxSource = new SAXSource(new InputSource(bufferedReader));
    String curDir = new File(".").getCanonicalPath();
    StreamSource xlstStreamSource = new StreamSource(new File(curDir + File.separator + "style.xsl"));
    File resultHTMLFile = new File(curDir + File.separator + "output.html");

    StreamResult streamResult = new StreamResult(resultHTMLFile);
    TransformerFactory factory = TransformerFactory.newInstance();
    Transformer transformer = factory.newTransformer(xlstStreamSource);
    transformer.transform((Source) saxSource, streamResult);
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    File stylesheet = new File("style.xsl");
    File xmlSource = new File("data.xml");

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document document = builder.parse(xmlSource);

    StreamSource stylesource = new StreamSource(stylesheet);
    Transformer transformer = TransformerFactory.newInstance().newTransformer(stylesource);
    Source source = new DOMSource(document);
    Result outputTarget = new StreamResult(new File("/tmp/x.csv"));
    transformer.transform(source, outputTarget);
}

From source file:Main.java

public static void main(String[] args) throws Exception {

    String xmlSample = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><tag><nested>hello</nested></tag>";
    String stylesheet = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"><xsl:output method=\"xml\" version=\"1.0\" indent=\"yes\"/><xsl:template match=\"node()|@*\"><xsl:copy><xsl:apply-templates select=\"node()|@*\"/></xsl:copy></xsl:template></xsl:stylesheet>";

    TransformerFactory factory = TransformerFactory.newInstance();

    Source xslSource = new StreamSource(new StringReader(stylesheet));
    Transformer transformer = factory.newTransformer(xslSource);

    Source source = new StreamSource(new StringReader(xmlSample));
    Result result = new StreamResult(System.out);

    transformer.transform(source, result);

}

From source file:Main.java

public static void main(String[] args) throws Exception {

    SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    System.out.println("schema factory instance obtained is " + sf);

    Schema schema = sf.newSchema(new File(args[0]));
    System.out.println("schema obtained is = " + schema);
    Validator validator = schema.newValidator();

    String fileName = args[1].toString();
    String fileName2 = args[2].toString();
    javax.xml.transform.Result xmlResult = new javax.xml.transform.stax.StAXResult(
            XMLOutputFactory.newInstance().createXMLStreamWriter(new FileWriter(fileName2)));
    javax.xml.transform.Source xmlSource = new javax.xml.transform.stax.StAXSource(getXMLEventReader(fileName));
    validator.validate(new StreamSource(args[1]));
    validator.validate(xmlSource, xmlResult);

}