将xml文件复制到文本文件中

本文关键字:文件 文本 复制 xml | 更新日期: 2023-09-27 18:26:59

我正在尝试将xml文件的内容复制到txt中。但每次我打开txt文件时,它都显示0。这是我的代码:

using System;
using System.Data;
using System.Text;
using System.IO;
using System.Xml;
using System.Xml.XPath;
public class Copy
{
    private static int Main(string[] args)
    {
        DataSet theDataSet = new DataSet();
        theDataSet.ReadXml(@"C:''Users'mchowdhury'Desktop'MediaInfo.xml"); 
        StreamWriter theWriter = new StreamWriter("test.xml");
        foreach (DataRow curRow in theDataSet.Tables[0].Rows)
        {
            foreach (object curObjectValue in curRow.ItemArray)
            {
                theWriter.Write(curObjectValue);
            }
        }
        theWriter.Close();
    }
}

有人能帮我提些建议吗?非常感谢。

将xml文件复制到文本文件中

如果您只是想写出数据并获得示例输出,请尝试以下操作:

DataSet theDataSet = new DataSet();
theDataSet.ReadXml(@"C:''Users'mchowdhury'Desktop'MediaInfo.xml");
StreamWriter theWriter = new StreamWriter("test.xml");
foreach (DataRow curRow in theDataSet.Tables[0].Rows)
{
    foreach (DataColumn curCol in theDataSet.Tables[0].Columns)
    {
        theWriter.Write(String.Format("{0} ", curRow[curCol]));
    }
}
theWriter.Close();