This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes I/O and Streams and the fly likes XML Encoding problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "XML Encoding problem" Watch "XML Encoding problem" New topic

XML Encoding problem

Jonathan Gerrish

Joined: Mar 25, 2003
Posts: 24

Having trouble with encoding related to an XML translation, the XML comes to me as a byte array, its encoded using extended latin. I think the following code should work, I set the encoding where I can, both on the creation of the input source, and prior to the transformation, however, the transformation does not work. (Output is just the header XML line)

InputSource dteInputSource =
new InputSource(new ByteArrayInputStream(contents[1].getBytes()));

Property outputProps = new Properties();
props.setProperty(OutputKeys.ENCODING, "ISO-8859-1");
transformer.transform( xslName, new SAXSource(dteInputSource),
new StreamResult(oagWriter), props);

However, when I preform the same transformation, but reading the input as a file: -

InputSource dteInputSource =
new InputSource(new FileInputStream("myInput.xml"));

The transformation works as expected. The transformer reference is a wrapper class for JAXP Transformer and I am sure this is OK, I think the problem is to do with how I am trying to encode the byte stream.

Can anyone shed some light on this for me?

Many thanks, Jonathan.
jQuery in Action, 2nd edition
subject: XML Encoding problem
Similar Threads
Incorrect encoding in XML
Proper use of an EntityResolver
How to remove carriage return and linefeeds from XML files
How to stream xml document to inputSource?
Named entity ref to hex code (using char mapping)