Use java.xml.transform to produce XML. This should prevent encoding issues.