c#读取xml文件,并将读取到的内容放入txt文档中

2024-11-23 10:36:52
推荐回答(1个)
回答1:

XmlDocument doc = new XmlDocument();
doc.Load(pathXML);
StreamWriter sw = new StreamWriter(patnTxt);
XmlNodeList nodeList = doc.DocumentElement.ChildNodes;
for (int i = 0; i < nodeList.Count; i++)
{
string id = nodeList[i].ChildNodes[0].InnerText;
string name = nodeList[i].ChildNodes[1].InnerText;
string score = nodeList[i].ChildNodes[2].InnerText;
sw.WriteLine(id + "," + name + "," + score);
}
sw.Close();