File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Services and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Web Services
Reply Bookmark ""problem of TransformerFactory "" Watch ""problem of TransformerFactory "" New topic
Author

"problem of TransformerFactory "

arul jothi
Greenhorn

Joined: Jan 28, 2005
Posts: 5
HI java ranch, I am very upset , because i am not able to get the newInstance for this javax.xml.transform.TransformerFactory .
Can any one plese help me to resolve this problem.Description About my Project:My project deals with xmls. Simply saying i need to xml file in java code by using the TransformerFactory . I am using tomcat Server. From the java documentation of TransformerFactory i come to know the terms called lib/jaxp.properties , and it's required to have the implementation class .Can any one tell me steps i need to follow:I am just using the the following code:
Thanks in advance
Makarand Parab
Ranch Hand

Joined: Dec 10, 2004
Posts: 121
Hi Arul
Try this way out
TransformerFactory tansfact = TransformerFactory.newInstance();
Transformer transformer = tansfact.newTransformer();
Checkout if ur getting transformer as null before u move ahead from this point

Are you trying to work with XML and XSL.

Let me know

Regards
Makarand Parab
arul jothi
Greenhorn

Joined: Jan 28, 2005
Posts: 5
HI Makarand Parab ,
Thanks for ur reply. the TransformerFactory object is null. So i am not able to get the Transformer from this factory. About ur second question, i am just creating a Document object then i am trying to create a xml file. For this i need a Transformer instance.

Thanks once again. Waiting for ur reply.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 32767
Do you have a library that's capable of creating transformers in your classpath? That would be either Xalan (from Jakarta) or Saxon (on SourceForge). Those two also come with instructions on how set them up, that is to say, what you need to put into the jaxp.properties file.


Android appsImageJ pluginsJava web charts
Makarand Parab
Ranch Hand

Joined: Dec 10, 2004
Posts: 121
Arul
To get the Document object u can code it this way rather than going for TransformerFactory.

Code
********
DocumentBuilderFactory dbf = DocumentBuilderFactory .newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc= db.newDocument();

this way u will get document object. Morever u need to have the parser jar file [one ur using xalan or xerces2] in the classpath. Transformer factory is mostly used when you are working with XML and XSL. For simple creation of document object to work with XML using dom u can use the above code.

Let me know

Regards
Makarand Parab
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 32767
Transformer factory is mostly used when you are working with XML and XSL.


Which is what the poster is doing. That is clear from the original post.

For simple creation of document object to work with XML using dom u can use the above code.


Which is what the poster is not doing. That also is clear from the original post. Your point is?
Jignesh Patel
Ranch Hand

Joined: Nov 03, 2001
Posts: 625

Transformer transformer = TransformerFactory.newInstance
().newTransformer();

It seems you are missing of adding xslt file.
It is supposed to be like this.

Transformer transformer = TransformerFactory.newInstance().newTransformer(inputXSL);

Also check whether the xlan processor is in your path.It comes by default with j2sdk1.4.

Instead of tomcat try following standalon class and see if it works.

import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.Result;
import javax.xml.transform.Transformer;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.Source;
import java.io.ByteArrayOutputStream;
public class Trans{
public static void main(String args[]){
try{


Source inputXML= new StreamSource(Thread.currentThread().getContextClassLoader().getResourceAsStream("source.xml"));

Source inputXSL = new StreamSource(Thread.currentThread().getContextClassLoader().getResourceAsStream("abc.xslt"));



Result result = new StreamResult(System.out);

TransformerFactory tFact = TransformerFactory.newInstance();
Transformer tf = tFact.newTransformer(inputXSL);

tf.setOutputProperty("indent", "yes");//

tf.transform(inputXML,result);



}catch(Exception e){
e.printStackTrace();
}


}
}
 
 
subject: "problem of TransformerFactory "
 
Threads others viewed
xml output formatting
how to update the attribute value
Having problem in modifying the value of node in xml
XML on the fly using servlets
java.security.AccessControlException
developer file tools