smne
smne

Reputation: 3

java xml parsing for ISO-8859-9

I'm trying to parse a string to xml for ISO-8859-9. My code is :

private Document stringToXML(String input)
{
  DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  DocumentBuilder builder;
  builder = factory.newDocumentBuilder();           
  return builder.parse(new ByteArrayInputStream(input.getBytes("ISO-8859-9")));     
}

if input includes just utf-8 characters, code runs correctly but input includes any special character like 'ğ' it throws "com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException:" How can i solve this problem?

Upvotes: 0

Views: 1547

Answers (2)

Joe Zitzelberger
Joe Zitzelberger

Reputation: 4263

If the input contains UTF-8 characters, then it is NOT an ISO-8859-9 stream. Parse it as UTF-8 or convert it to ISO-8859-9 before trying to parse. You only ever get one character set per document, trying to mix makes the whole thing meaningless.

Upvotes: 1

McDowell
McDowell

Reputation: 108949

Parse a StringReader via an InputSource.

Upvotes: 1

Related Questions