我修改了xml文件后,文件中的中文就都变成了乱码了
初学,请高手帮忙~~~
public bool New()
{
XmlDocument doc=new XmlDocument();
doc.Load("GameServiceSet.xml");
//create a new 'Game' element
XmlElement newGame=doc.CreateElement("Game");
//set some attributes
int num=GetNum()+1;
newGame.SetAttribute("id",num.ToString());
//create a new 'gamename' element
XmlElement newGamename=doc.CreateElement("gamename");
newGamename.InnerText="斗地主";
newGame.AppendChild(newGamename);
//create new people element
XmlElement newPeople=doc.CreateElement("people");
newGame.AppendChild(newPeople);
//set some attributes
newPeople.SetAttribute("num","10");
newPeople.SetAttribute("now","1");
//create new person element
XmlElement newPerson=doc.CreateElement("person");
newPeople.AppendChild(newPerson);
newPerson.SetAttribute("cs","true");
//create new Pname element
XmlElement newName=doc.CreateElement("name");
newName.InnerText="Player1";
newPerson.AppendChild(newName);
//create new IP element
XmlElement newIP=doc.CreateElement("IP");
newIP.InnerText="192.168.0.15";
newPerson.AppendChild(newIP);
//add to the current document
doc.DocumentElement.AppendChild(newGame);
FileStream fs = new FileStream("GameServiceSet.xml" ,FileMode.OpenOrCreate);
XmlTextWriter tr=new XmlTextWriter(fs,null);
tr.WriteDocType
tr.Formatting=Formatting.Indented;
doc.WriteContentTo(tr);
tr.Close();
fs.Close();
return true;
}
我调用这个函数后,我的xml文件中的中文就都变成乱码了???