Hi there,
I am facing a strange problem which I haven't anticipated.
I have an xslt stylesheet as a text file in my java class file
location. I read the file contents and create a transformer instance
for repeated use within the program. Following is the sample code
snippet I use.
.....
.....
m_transformerFactory = (TransformerFactory)
TransformerFactory.newInstance();
InputStream inputStream = this.getClass().getResourceAsStream(
fileName );
int totalSize = inputStream.available();
byte xsltFilterBytes[] = new byte[totalSize];
inputStream.read( xsltFilterBytes);
StreamSource xsltFilterSource = new StreamSource(
new ByteArrayInputStream(
xsltFilterBytes ));
// Create the Transfomer instances for the stylesheet.
m_xsltFilterTransformer = m_transformerFactory.newTransformer(
xsltFilterSource );
.....
.....
This code works fine when working with the class file locally. But when
packaged as a jar file and reading from there it throws
TransformerConfigurationException when tries to create the
newTransfomer. The file is read correctly, the contents are the same in
both cases. Following is the error I get.
javax.xml.transform.TransformerConfigurationException:
javax.xml.transform.TransformerException:
org.xml.sax.SAXParseException: An invalid XML character (Unicode: 0x0)
was found in the element content of the document.
Instead of reading as byte stream I tried using the class loader with
URL and still the TransformerFactory is not happy. Why would it
complain about the Unicode character error? I'm running out of ideas.
Please someone help me to resolve this problem. This has become a
show-stopper in my case.
Thanks,
Sheen