You could write an XMLFilter [1] which wraps the XMLReader and pass that 
to the Transformer instead.

[1] 
http://xerces.apache.org/xerces2-j/javadocs/api/org/xml/sax/XMLFilter.html

Michael Glavassevich
XML Technologies and WAS Development
IBM Toronto Lab
E-mail: mrgla...@ca.ibm.com
E-mail: mrgla...@apache.org

Harsh_Gupta <har...@adobe.com> wrote on 12/06/2012 09:11:15 AM:

> We want to get startDocument callback in following scenarios:
> - When any input xml file is parsed before doing transformation.
> - Or when any file is opened using document function of XSLT.
> 
> Even after registering our own ContentHandler object in xmlReader 
object, we
> aren't getting any callbacks. While debugging the xalan code, I found 
that
> before parsing the input XML file, xalan is overriding the user supplied
> ContentHandler object, LexicalHandler object and DTDHandler object. 
> 
> Is there any way/workaround to get the callbacks? Any help would be
> appreciated.
> 
> The code that we are using is as follows:
> 
> String inputFilePath =
> "C:\\Users\\harshg.ADOBENET\\Desktop\\BugFiles\\document\\entity.xml";
> String xslFilePath =
> "C:\\Users\\harshg.ADOBENET\\Desktop\\BugFiles\\document\\vendor.xsl";
> String outputFilePath =
> "C:/Users/harshg.ADOBENET/Desktop/BugFiles/document/Data-out1.xml";
> 
> //1) Created the XMLReader and registered the ContentHandler as follows: 

> XMLReader m_xmlReader =
> SAXParserFactory.newInstance().newSAXParser().getXMLReader();
> m_xmlReader.setContentHandler(new FMSAXEventHandler());
> 
> //2) Created the TransformerFactory as follows:
> System.setProperty("javax.xml.transform.TransformerFactory",
> "org.apache.xalan.processor.TransformerFactoryImpl");
> TransformerFactory m_tFactory = TransformerFactory.newInstance();
> m_tFactory.setURIResolver(new FMURIResolver());
> 
> //3) Created the transformer as follows:
> Transformer transformer = m_tFactory.newTransformer(new StreamSource(new
> File(xslFilePath).toURI().toURL().toExternalForm()));
> 
> //4) Transforming the input file as follows:
> transformer.transform(new SAXSource(m_xmlReader, new InputSource(new
> File(inputFilePath).toURI().toURL().toExternalForm())), new 
StreamResult(new
> OutputStreamWriter(new FileOutputStream(outputFilePath), "UTF-8")));
> 
> 
> Thanks!
> Harsh Gupta
> Adobe Systems

Reply via email to