You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by "Krishna Mohan Meduri[Temp]" <Kr...@eng.sun.com> on 2000/11/17 09:37:58 UTC

Re: [Problem] with newXMLFilter of SAXTransformerFactory.

Hi Scott,

In the following code, I used DOMSource as argument for newXMLFilter. I get one 
output which I have attached.
-------------------------------------------------------------------------------
    public static void main(String[] argv) throws SAXException, IOException,
    	TransformerConfigurationException, ParserConfigurationExcpetion {

        TransformerFactory tfactory = TransformerFactory.newInstance();

        // The transformer will use a SAX parser as it's reader.
        XMLReader reader = XMLReaderFactory.createXMLReader();
        reader.setContentHandler(new ExampleContentHandler());

        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = dbf.newDocumentBuilder();
        Document document = docBuilder.parse(new File("cities.xsl"));
        Node node = (Node)document;
        DOMSource domSource= new DOMSource(node);

        SAXTransformerFactory saxTFactory = (SAXTransformerFactory)tfactory;
        XMLFilter filter = saxTFactory.newXMLFilter(domSource);

        filter.setParent(reader);
        filter.parse(new InputSource("cities.xml"));
    } //end of main()
-------------------------------------------------------------------------------

If I use SAXSource as argument for newXMLFilter() using the following code, I 
get a different output which I attached.

-------------------------------------------------------------------------------
         InputSource is = new InputSource(new FileInputStream("cities.xsl"));
         SAXSource saxSource = new SAXSource();
         saxSource.setInputSource(is);

         SAXTransformerFactory saxTFactory = (SAXTransformerFactory)tfactory;
         XMLFilter filter = saxTFactory.newXMLFilter(saxSource);
--------------------------------------------------------------------------------

Why is it showing nulls when I use DOMSource and spaces when I use SAXSource?
Could you tell me the reason behind it.

Regards,
krishna.