Re: ContentHandler.startDocument callback not coming, while transforming the input XML File.
Michael Glavassevich <[email protected]> Tue, 12 Jun 2012 10:38:34 -0400
| Newsgroups | gmane.text.xml.xalan.java.user |
|---|---|
| Message-ID | <OFA9AF7BEE.A21C9E6B-ON85257A1B.00501697-85257A1B.00506F23@ca.ibm.com> |
This is a multipart message in MIME format. --=_alternative 00506F2085257A1B_= Content-Type: text/plain; charset="US-ASCII" 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: [email protected] E-mail: [email protected] Harsh_Gupta <[email protected]> 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 --=_alternative 00506F2085257A1B_= Content-Type: text/html; charset="US-ASCII" <tt><font size=2>You could write an XMLFilter [1] which wraps the XMLReader and pass that to the Transformer instead.</font></tt> <br> <br><tt><font size=2>[1] </font></tt><a href="http://xerces.apache.org/xerces2-j/javadocs/api/org/xml/sax/XMLFilter.html"><tt><font size=2>http://xerces.apache.org/xerces2-j/javadocs/api/org/xml/sax/XMLFilter.html</font></tt></a> <br> <br><tt><font size=2>Michael Glavassevich<br> XML Technologies and WAS Development<br> IBM Toronto Lab<br> E-mail: [email protected]</font></tt> <br><tt><font size=2>E-mail: [email protected]</font></tt> <br> <br><tt><font size=2>Harsh_Gupta <[email protected]> wrote on 12/06/2012 09:11:15 AM:<br> <br> > We want to get startDocument callback in following scenarios:<br> > - When any input xml file is parsed before doing transformation.<br> > - Or when any file is opened using document function of XSLT.<br> > <br> > Even after registering our own ContentHandler object in xmlReader object, we<br> > aren't getting any callbacks. While debugging the xalan code, I found that<br> > before parsing the input XML file, xalan is overriding the user supplied<br> > ContentHandler object, LexicalHandler object and DTDHandler object. <br> > <br> > Is there any way/workaround to get the callbacks? Any help would be<br> > appreciated.<br> > <br> > The code that we are using is as follows:<br> > <br> > String inputFilePath =<br> > "C:\\Users\\harshg.ADOBENET\\Desktop\\BugFiles\\document\\entity.xml";<br> > String xslFilePath =<br> > "C:\\Users\\harshg.ADOBENET\\Desktop\\BugFiles\\document\\vendor.xsl";<br> > String outputFilePath =<br> > "C:/Users/harshg.ADOBENET/Desktop/BugFiles/document/Data-out1.xml";<br> > <br> > //1) Created the XMLReader and registered the ContentHandler as follows: <br> > XMLReader m_xmlReader =<br> > SAXParserFactory.newInstance().newSAXParser().getXMLReader();<br> > m_xmlReader.setContentHandler(new FMSAXEventHandler());<br> > <br> > //2) Created the TransformerFactory as follows:<br> > System.setProperty("javax.xml.transform.TransformerFactory",<br> > "org.apache.xalan.processor.TransformerFactoryImpl");<br> > TransformerFactory m_tFactory = TransformerFactory.newInstance();<br> > m_tFactory.setURIResolver(new FMURIResolver());<br> > <br> > //3) Created the transformer as follows:<br> > Transformer transformer = m_tFactory.newTransformer(new StreamSource(new<br> > File(xslFilePath).toURI().toURL().toExternalForm()));<br> > <br> > //4) Transforming the input file as follows:<br> > transformer.transform(new SAXSource(m_xmlReader, new InputSource(new<br> > File(inputFilePath).toURI().toURL().toExternalForm())), new StreamResult(new<br> > OutputStreamWriter(new FileOutputStream(outputFilePath), "UTF-8")));<br> > <br> > <br> > Thanks!<br> > Harsh Gupta<br> > Adobe Systems</font></tt> --=_alternative 00506F2085257A1B_=--