1 16 19 20 import java.io.IOException ; 21 22 import javax.xml.transform.TransformerConfigurationException ; 23 import javax.xml.transform.TransformerException ; 24 import javax.xml.transform.TransformerFactory ; 25 import javax.xml.transform.sax.SAXResult ; 26 import javax.xml.transform.sax.SAXSource ; 27 import javax.xml.transform.sax.SAXTransformerFactory ; 28 import javax.xml.transform.sax.TransformerHandler ; 29 import javax.xml.transform.stream.StreamSource ; 30 31 import org.apache.xml.serializer.Serializer; 32 import org.apache.xml.serializer.SerializerFactory; 33 import org.apache.xml.serializer.OutputPropertiesFactory; 34 import org.xml.sax.SAXException ; 35 import org.xml.sax.XMLReader ; 36 import org.xml.sax.helpers.XMLReaderFactory ; 37 38 43 public class Pipe 44 { 45 public static void main(String [] args) 46 throws TransformerException , TransformerConfigurationException , 47 SAXException , IOException 48 { 49 TransformerFactory tFactory = TransformerFactory.newInstance(); 51 if (tFactory.getFeature(SAXSource.FEATURE) && tFactory.getFeature(SAXResult.FEATURE)) 54 { 55 SAXTransformerFactory saxTFactory = ((SAXTransformerFactory ) tFactory); 57 TransformerHandler tHandler1 = saxTFactory.newTransformerHandler(new StreamSource ("foo1.xsl")); 59 TransformerHandler tHandler2 = saxTFactory.newTransformerHandler(new StreamSource ("foo2.xsl")); 60 TransformerHandler tHandler3 = saxTFactory.newTransformerHandler(new StreamSource ("foo3.xsl")); 61 62 XMLReader reader = XMLReaderFactory.createXMLReader(); 64 reader.setContentHandler(tHandler1); 65 reader.setProperty("http://xml.org/sax/properties/lexical-handler", tHandler1); 66 67 tHandler1.setResult(new SAXResult (tHandler2)); 68 tHandler2.setResult(new SAXResult (tHandler3)); 69 70 Serializer serializer = SerializerFactory.getSerializer 72 (OutputPropertiesFactory.getDefaultMethodProperties("xml")); 73 serializer.setOutputStream(System.out); 74 tHandler3.setResult(new SAXResult (serializer.asContentHandler())); 75 76 reader.parse("foo.xml"); 79 } 80 } 81 } 82
| Popular Tags
|