Use the transform.TransformerFactory plugability in the JAXP API : Transform « XML « Java






Use the transform.TransformerFactory plugability in the JAXP API

      

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

public class MainClass {
  public static void main(String[] args) throws TransformerException,
      TransformerConfigurationException, FileNotFoundException, IOException {
    if (args.length != 3) {
      System.out.println("Usage: java jaxpTransform inXML inXSLT outFile");
      System.exit(0);
    }
    FileOutputStream outstream = new FileOutputStream(args[2]);

    TransformerFactory tfactory = TransformerFactory.newInstance();
    StreamSource insource = new StreamSource(args[0]);
    StreamSource inxsl = new StreamSource(args[1]);
    StreamResult sresult = new StreamResult(outstream);
    Transformer transformer = tfactory.newTransformer(inxsl);
    transformer.transform(insource, sresult);
  }
}

   
    
    
    
    
  








Related examples in the same category

1.XML transformation
2.A Program That Performs XML Transformations
3.XSLT I18N
4.Processing XML Documents Partially
5.Set the TransformerFactory system property to generate and use translets
6.Transforming DOM Node to HTML with JAXP
7.Transformer with parameters
8.Create an XML file and attach an XSL
9.Applying XSLT Stylesheets
10.Catch TransformerException
11.Formatting an XML file using Transformer
12.Transforming an XML File with XSL into a DOM Document
13.XML input, output and transform utilities
14.XSL transformations: It applies a transformation to a set of employee recordsXSL transformations: It applies a transformation to a set of employee records
15.How to write an XML file. It saves a file describing a modern drawing in SVG format.
16.Applies a stylesheet to a given xml document.
17.Applies a stylesheet (that receives parameters) to a given xml document.
18.Apply some indentiation to some XML.