FileDocCategorySizeDatePackage
SimpleJaxp.javaAPI DocExample1404Sun Sep 02 14:59:02 BST 2001chap5

SimpleJaxp

public class SimpleJaxp extends Object
A simple demo of JAXP 1.1

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)
Accept two command line arguments: the name of an XML file, and the name of an XSLT stylesheet. The result of the transformation is written to stdout.

        if (args.length != 2) {
            System.err.println("Usage:");
            System.err.println("  java " + SimpleJaxp.class.getName()
                    + " xmlFileName xsltFileName");
            System.exit(1);
        }

        File xmlFile = new File(args[0]);
        File xsltFile = new File(args[1]);

        javax.xml.transform.Source xmlSource =
                new javax.xml.transform.stream.StreamSource(xmlFile);
        javax.xml.transform.Source xsltSource =
                new javax.xml.transform.stream.StreamSource(xsltFile);
        javax.xml.transform.Result result =
                new javax.xml.transform.stream.StreamResult(System.out);

        // create an instance of TransformerFactory
        javax.xml.transform.TransformerFactory transFact =
                javax.xml.transform.TransformerFactory.newInstance();

        javax.xml.transform.Transformer trans =
                transFact.newTransformer(xsltSource);

        trans.transform(xmlSource, result);