Jak dołączyć kodowanie podczas tworzenia plików XML
Chcę utworzyć plik XML do przechowywania informacji. Używam następującego kodu. Chciałbym wiedzieć, jak określić kodowanie tego pliku w kodzie.
Kiedy próbuję odczytać ten plik w innej formie, znaki po japońsku są zniekształcone.
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);