简体   繁体   中英

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.

You have an error. You are writing the csv object for every line, instead of line .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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