I want to create an XML file to store information. I am using the following code. I would like to know how to specify the encoding for this file in code.
When I try to read this file in another form the characters in Japanese are distorted.
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);