【问题标题】:how to output the child node from a xml file using C# into csv file如何使用 C# 将 xml 文件中的子节点输出到 csv 文件中
【发布时间】:2015-09-02 16:59:15
【问题描述】:

我有一个输出 CSV 文件的应用程序。在项目中,我有一个包含 url 的 xml 配置文件。

<url>http://localhost/test</url>

我想要实现的是将xml文件中的属性输出到csv文件中(例如http://localhost/test)。

我需要将它输出到file.WriteLine行代码中,但我不知道如何输出xml文件中的url内容。

我已经创建了一个 XmlTextReader,但仍然无法输出 url

这里有我的部分代码:

int count = xml.GetElementsByTagName("url").Count;

for (int i = 0; i < count; ++i)
    {
     url.Add(xml.GetElementsByTagName("url")[i].InnerText);
    }
XmlTextReader reader = new XmlTextReader("config.xml");
using (StreamWriter file = new StreamWriter(fs))                    
{
    file.WriteLine("ProjectID, ProjectTitle,PublishStatus,Length");
    for (int s = 0; s < pr.Length; ++s)
    {
        string[] UsersIDS = new string[] {""};
        UsersIDS = db.GetUsersList(pr[s].ProjectID);
        file.WriteLine( pr[s].ProjectID + '"' + ',' + '"' + pr[s].ProjectTitle + '"' + ',' + pr[s].PublishStatus + '"' + ',' + UsersIDS.Length); 

}//end of for

【问题讨论】:

    标签: c# xml export-to-csv console.writeline


    【解决方案1】:

    经过测试,我通过添加以下内容使其工作:

    url[i].ToString()
    

    还是谢谢

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-28
      • 2011-07-30
      • 1970-01-01
      • 2013-03-26
      • 2020-02-02
      • 1970-01-01
      相关资源
      最近更新 更多