FileDocCategorySizeDatePackage
Streams.javaAPI DocExample1737Sun Sep 02 14:59:00 BST 2001chap5

Streams

public class Streams extends Object
A simple demo of JAXP 1.1 StreamSource and StreamResult. This program downloads the XML specification from the W3C and prints it to a temporary file.

Fields Summary
private static final String
IDENTITY_XSLT
private static String
xmlSystemId
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)



          
             

        // show how to read from a system identifier and a Reader
        Source xmlSource = new StreamSource(xmlSystemId);
        Source xsltSource = new StreamSource(
                new StringReader(IDENTITY_XSLT));

        // send the result to a file
        File resultFile = File.createTempFile("Streams", ".xml");
        Result result = new StreamResult(resultFile);

        System.out.println("Results will go to: "
                + resultFile.getAbsolutePath());

        // get the factory
        TransformerFactory transFact = TransformerFactory.newInstance();

        // get a transformer for this particular stylesheet
        Transformer trans = transFact.newTransformer(xsltSource);

        // the next line will also perform an identity copy
//        Transformer trans = transFact.newTransformer();

        // do the transformation
        trans.transform(xmlSource, result);