Skip to main content

Problems with stax transformation

1 reply [Last post]
getaceres
Offline
Joined: 2007-05-28

Hello, I'm trying to do some XML transformation in a Web Service using Axis2. Since it uses a StaX document model, I've downloaded JAXP 1.4.2 and I've made a simple test like this:

public static OMElement getInvocation(String xsltLocation, OMElement data) {
try {
TransformerFactory transformFactory = TransformerFactory.newInstance();

StAXOMBuilder builder = new StAXOMBuilder(xsltLocation);
OMElement xsltElem = builder.getDocumentElement();
StAXSource source = new StAXSource(xsltElem.getXMLStreamReader());

//Templates templates = transformFactory.newTemplates(source);
//Transformer transformer = templates.newTransformer();
Transformer transformer = transformFactory.newTransformer();

if (transformer != null) {
StAXSource xmlSource = new StAXSource(data.getXMLStreamReader());

StAXResult result = new StAXResult(StAXUtils.createXMLStreamWriter(System.out));

if (xmlSource != null) {
if (result != null) {
transformer.transform(xmlSource, result);
}
else {
System.out.println("Result is null");
}
}
else {
System.out.println("XML Source is null");
}
}
else {
System.out.println("Got null transformer");
}

} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (TransformerConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (TransformerFactoryConfigurationError e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XMLStreamException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (TransformerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return null;
}

When I use Templates templates = transformFactory.newTemplates(source); I get a null reference, which as the documentation says, should not happen (it says explicitly that it never returns null, strange).

If I use the identity, I pass this point but I get the following error:

javax.xml.transform.TransformerException: No se puede transformar un resultado de tipo javax.xml.transform.stax.StAXResult

Which is something like "Could not create a result of type javax.xml.transform.stax.StAXResult". I don't know if it may be a problem with Axiom failing to implement StaX API or if I'm doing something wrong (or it's a JAXP bug).
I've tried with JDK 1.5 and 1.6 and they give the same result.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
getaceres
Offline
Joined: 2007-05-28

I answer to myself. It was because Axis2 has its own version of Xalan that only implements JAXP 1.3. Putting the JAXP jars ahead in the classpath worked for me.