怎么将xml文件转存为txt文件 C#
private void button1_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string strPath = openFileDialog1.FileName;
XmlDocument doc = new XmlDocument();
doc.Load(strPath);
string pathtxt = "dataset.txt";
StreamWriter sw = new StreamWriter(pathtxt);
XmlNodeList nodeList = doc.DocumentElement.ChildNodes;
for (int i = 0; i < nodeList.Count; i++)
{
string Id = nodeList[i].ChildNodes[0].InnerText;
string PostTypeId = nodeList[i].ChildNodes[1].InnerText;
string ParentID = nodeList[i].ChildNodes[2].InnerText;
string AcceptedAnswerId = nodeList[i].ChildNodes[3].InnerText;
string CreationDate = nodeList[i].ChildNodes[4].InnerText;
string Score = nodeList[i].ChildNodes[5].InnerText;
string ViewCount = nodeList[i].ChildNodes[6].InnerText;
string Body = nodeList[i].ChildNodes[7].InnerText;
string OwnerUserId = nodeList[i].ChildNodes[8].InnerText;
string LastEditorUserId = nodeList[i].ChildNodes[9].InnerText;
string LastEditorDisplayName = nodeList[i].ChildNodes[10].InnerText;
string LastEditDate = nodeList[i].ChildNodes[10].InnerText;
string LastActivityDate = nodeList[i].ChildNodes[11].InnerText;
string CommunityOwnedDate = nodeList[i].ChildNodes[12].InnerText;
string ClosedDate = nodeList[i].ChildNodes[13].InnerText;
string Title = nodeList[i].ChildNodes[14].InnerText;
string Tags = nodeList[i].ChildNodes[15].InnerText;
string AnswerCount = nodeList[i].ChildNodes[16].InnerText;
string CommentCount = nodeList[i].ChildNodes[17].InnerText;
string FavoriteCount = nodeList[i].ChildNodes[18].InnerText;
sw.WriteLine(Id+ " " + PostTypeId + " " + ParentID + " " + AcceptedAnswerId + " " + CreationDate + " " +
Score + " " + ViewCount + " " + Body + " " + OwnerUserId + " " + LastEditorUserId + " " + LastEditorDisplayName +
" " + LastEditDate + " " + LastActivityDate + " " + CommunityOwnedDate + " " + ClosedDate + " " + Title +
" " + Tags + " " + AnswerCount + " " + CommentCount + " " + FavoriteCount);
}
sw.Close();
我想将xml文件里的东西转存成txt,但是他一直提示那个nodelist.childnode.innertext没有实例化的对象,求帮助啊~谢谢各位大神