javax.xml.transform.TransformerException durin XSL Transformation in Java
Hi,
Below is my piece of code where i access a web service that returns a xml as a string. I apply a xsl tranformation on it and try to store the result as a string. I get this error message
javax.xml.transform.TransformerException: Result object passed to''{0}'' is invalid.
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.getOutputHandler(Unknown Source)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(Unknown Source)
at NewService.main(NewService.java:52)
My Code:
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;
import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
publicclass NewService{
/**
* @param args
*/
publicstaticvoid main(String[] args){
// TODO Auto-generated method stub
String endPoint ="http://localhost:8080/SampleDynamicWebProj/services/SampleClient";
Service service =new Service();
Call callOne;
try{
callOne = (Call) service.createCall();
callOne.setTargetEndpointAddress(new URL(endPoint));
callOne.setOperationName(new QName("http://DefaultNamespace",
"getXMLString"));
String concated = (String) callOne.invoke(new Object[]{"s"});
InputStream xsltFile =new FileInputStream("xslpackage/empTran.xsl");
Source xmlSource =new StreamSource(new StringReader(concated));
Source xsltSource =new StreamSource(xsltFile);
TransformerFactory transFact =
TransformerFactory.newInstance();
Transformer trans = transFact.newTransformer(xsltSource);
Result result =new StreamResult();
trans.transform(xmlSource, result);
System.out.println(result.toString());
}catch (ServiceException e){
e.printStackTrace();
}catch (MalformedURLException e){
e.printStackTrace();
}catch (RemoteException e){
e.printStackTrace();
}catch (FileNotFoundException e){
e.printStackTrace();
}catch (TransformerConfigurationException e){
e.printStackTrace();
}catch (TransformerException e){
e.printStackTrace();
}
}
}
I get the transformed XML into a Result object, but when i do a toString() oon it, i get the above exception.
any help wil be appreciated,
Dilip

