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.stream.StreamSource ; 29 30 import org.apache.xml.serializer.Serializer; 31 import org.apache.xml.serializer.SerializerFactory; 32 import org.apache.xml.serializer.OutputPropertiesFactory; 33 import org.xml.sax.InputSource ; 34 import org.xml.sax.SAXException ; 35 import org.xml.sax.XMLFilter ; 36 import org.xml.sax.XMLReader ; 37 import org.xml.sax.helpers.XMLReaderFactory ; 38 39 44 public class UseXMLFilters 45 { 46 public static void main(String [] args) 47 throws TransformerException , TransformerConfigurationException , 48 SAXException , IOException 49 { 50 TransformerFactory tFactory = TransformerFactory.newInstance(); 52 if (tFactory.getFeature(SAXSource.FEATURE) && tFactory.getFeature(SAXResult.FEATURE)) 55 { 56 SAXTransformerFactory saxTFactory = ((SAXTransformerFactory ) tFactory); 58 XMLFilter xmlFilter1 = saxTFactory.newXMLFilter(new StreamSource ("foo1.xsl")); 60 XMLFilter xmlFilter2 = saxTFactory.newXMLFilter(new StreamSource ("foo2.xsl")); 61 XMLFilter xmlFilter3 = saxTFactory.newXMLFilter(new StreamSource ("foo3.xsl")); 62 63 XMLReader reader = XMLReaderFactory.createXMLReader(); 65 66 xmlFilter1.setParent(reader); 68 69 xmlFilter2.setParent(xmlFilter1); 71 72 xmlFilter3.setParent(xmlFilter2); 74 75 Serializer serializer = SerializerFactory.getSerializer 77 (OutputPropertiesFactory.getDefaultMethodProperties("xml")); 78 serializer.setOutputStream(System.out); 79 xmlFilter3.setContentHandler(serializer.asContentHandler()); 80 81 xmlFilter3.parse(new InputSource ("foo.xml")); 95 } 96 } 97 } 98 | Popular Tags |