[jdom-interest] Todo list [eg]

Rosen, Alex arosen at silverstream.com
Sat Apr 28 14:00:37 PDT 2001

>> XMLOutputter.printDeclaration() knows that it should write encoding="UTF-8"
>> rather than encoding="UTF8". I think we need to add a long list of
>> from Java encoding names to standard encoding names, or we'll print the
>> thing when using other encodings.
> Do you have other examples where it's necessary?

See the code below. This will print encoding="ISO8859_1" in the XML, which is
wrong, and Xerces will give you an error (unless you turn on

Actually this is less serious than I previously thought. I had thought that XML
standard encoding names were not accepted by Java, but they are. The string you
get back from OutputStreamWriter.getEncoding() is always the Java-style (i.e.
wrong) name, but you can pass in a proper name to the constructor. So we could
just make it a requirement that you pass in a valid XML-style name to
XMLOutputter. (Possibly with a special case for "UTF8", for historical reasons,
though I'm not really sure why this should be treated differently.)

> P.S.  Care to submit a patch to the TODO?

Not sure how that would be different than the e-mail message I sent...


import java.io.*;
import org.jdom.*;
import org.jdom.output.*;
import org.jdom.input.*;

public class EncodingTest
	public static void main(String[] args)
			// Create the document.
			Element root = new Element("r\u00f6\u00f6t");
			Document doc = new Document(root);

			// Output it using the Java-style encoding name "ISO8859_1"
			// instead of the standard XML-style name "ISO-8859-1".
			XMLOutputter outputter = new XMLOutputter("\t", true, "ISO8859_1");
			OutputStream out = new FileOutputStream(args[0]);
			outputter.output(doc, out);

			// Read in the file. This will fail, because Xerces chokes on "ISO8859_1".
			SAXBuilder builder = new SAXBuilder();
			InputStream in = new FileInputStream(args[0]);
		catch(Exception ex)

More information about the jdom-interest mailing list