// Collection of code snippets by Arne VajhÃ¸j 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.io.*;
import javax.xml.parsers.*;

import org.w3c.dom.*;

import com.sun.org.apache.xml.internal.serialize.*;

public class WriteXmlUTF16 {
    public static void main(String[] args) throws Exception {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document doc = db.newDocument();
        Element info = doc.createElement("info");
        info.appendChild(doc.createTextNode("ÆØÅ"));
        doc.appendChild(info);
        OutputFormat fmt = new OutputFormat();
        fmt.setIndenting(true);
        fmt.setEncoding("UTF-16");
        XMLSerializer ser = new XMLSerializer(new OutputStreamWriter(new FileOutputStream("C:\\test.xml"), "UTF-16"), fmt);
        ser.serialize(doc);
    }
}
