我想创建一个 XML 文件来存储信息。我正在使用以下代码。我想知道如何在代码中指定这个文件的编码。
当我尝试以另一种形式读取此文件时,日语中的字符会失真。
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);