Como incluir codificação ao criar arquivos xml
Eu quero criar um arquivo XML para armazenar informações. Estou usando o seguinte código. Eu gostaria de saber como especificar a codificação para este arquivo no código.
Quando tento ler esse arquivo de outra forma, os caracteres em japonês são distorcidos.
XmlDocument writer = new XmlDocument();
XmlElement root = writer.CreateElement("PatientFile");
writer.AppendChild(root);
XmlElement ID = writer.CreateElement("ID");
if (!string.IsNullOrEmpty(_a2Data.CurrentRecordId))
{
ID.InnerText = _a2Data.CurrentRecordId;
}
root.AppendChild(ID);
XmlElement patientID = writer.CreateElement("PatientID");
if (!string.IsNullOrEmpty(_a2Data.PatId))
{
patientID.InnerText = _a2Data.PatId;
}
root.AppendChild(patientID);
XmlElement patientName = writer.CreateElement("PatientName");
if (!string.IsNullOrEmpty(_a2Data.PatName))
{
patientName.InnerText = _a2Data.PatName;
}
root.AppendChild(patientName);
XmlElement room = writer.CreateElement("Room");
if (!string.IsNullOrEmpty(_a2Data.RoomName))
{
room.InnerText = _a2Data.RoomName;
}
root.AppendChild(room);
string folderName = ConfigurationManager.AppSettings["PatientXMLFiles"];
if (!Directory.Exists(folderName))
Directory.CreateDirectory(folderName);
string fileName = ConfigurationManager.AppSettings["PatientXMLFiles"] + @"\" + _a2Data.CurrentRecordId + ".xml";
writer.Save(fileName);