public void outputXMLToFile(Document doc, String fileName)
{
try {
FileWriter writer = new FileWriter(fileName);
//Pay attention to the OutputFormat constructor, which set the GB2312
org.apache.xml.serialize.OutputFormat outputFormat =
new org.apache.xml.serialize.OutputFormat(doc, "GB2312", true);