Default output encoding is UTF-8
Can change this in several ways using methods of
XMLOutputter
import java.math.*;
import java.io.*;
import org.jdom.*;
import org.jdom.output.XMLOutputter;
public class FibonacciJDOMLatin1 {
public static void main(String[] args) {
Element root = new Element("Fibonacci_Numbers");
BigInteger low = BigInteger.ZERO;
BigInteger high = BigInteger.ONE;
for (int i = 0; i <= 25; i++) {
Element fibonacci = new Element("fibonacci");
Attribute index = new Attribute("index", String.valueOf(i));
fibonacci.addAttribute(index);
fibonacci.setContent(low.toString());
BigInteger temp = high;
high = high.add(low);
low = temp;
root.addChild(fibonacci);
}
Document doc = new Document(root);
// serialize it into a file
try {
FileOutputStream out = new FileOutputStream("fibonacci_8859_1.xml");
XMLOutputter serializer = new XMLOutputter();
serializer.output(doc, out, "8859_1");
out.flush();
out.close();
}
catch (IOException e) {
System.err.println(e);
}
}
}