简体   繁体   English

How to output data on to a CSV file, after extracting data from XML file using LINQ C#?

[英]How to output data on to a CSV file, after extracting data from XML file using LINQ C#?

I have an XML schema file, and I am trying to pull the attribute values for each of the element, that is in this XMl Schema file.我有一个 XML 架构文件,我正在尝试提取每个元素的属性值,即在此 XMl 架构文件中。

You have an error.你有一个错误。 You are writing the csv object for every line, instead of line .您正在为每一行而不是line编写csv object 。

Additionally, you can restructure the writing logic as such:此外,您可以这样重构编写逻辑:

using (StreamWriter writeToFile = new StreamWriter(@"igxSpec.csv"))
{
    foreach (string line in csv)
    {
        writeToFile.WriteLine(line);
    }
}

This makes it a little cleaner, and automatically does the cleanup after StreamWriter is done writing the content to file.这使它更干净一些,并在StreamWriter完成将内容写入文件后自动进行清理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM