convert this xml into csv file

See the attached file. I need to convert this into a csv file, where each row is an employee record.

I need this done in C#, can someone please help???
Who is Participating?
Jens FiedererConnect With a Mentor Test Developer/ValidatorCommented:
With no header lines and only employee data lines, you could use:

            var doc = new XmlDocument();
            var columns = doc.SelectNodes("//COLUMNS[COLUMN/@NAME=\"Employees.Reference\"]");
            var x = String.Join(Environment.NewLine, from XmlNode record in columns
                                                         String.Join(",", (from XmlNode column in record.SelectNodes("COLUMN")
                                                                           select column.InnerText)));

Open in new window

Jens FiedererTest Developer/ValidatorCommented:
A typical CSV file only has a single record type, your XML file has two of them (presumably parent child).

Do you want company and employee lines interspersed?

Suppose there is more than one PAGE, do we just ignore pages?
Jens FiedererTest Developer/ValidatorCommented:
Or maybe we just ignore company lines and do employee lines, that is what you seem to be asking you need a header line in the CSV output?
Jens FiedererTest Developer/ValidatorCommented:
(I filter for Employees.Reference to avoid output of any Company data)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.