Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 120
  • Last Modified:

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???
EMPDETP---Test-Data.xml
0
dipster307
Asked:
dipster307
  • 4
1 Solution
 
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?
0
 
Jens FiedererTest Developer/ValidatorCommented:
Or maybe we just ignore company lines and do employee lines, that is what you seem to be asking for....do you need a header line in the CSV output?
0
 
Jens FiedererTest Developer/ValidatorCommented:
With no header lines and only employee data lines, you could use:

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

Open in new window

0
 
Jens FiedererTest Developer/ValidatorCommented:
(I filter for Employees.Reference to avoid output of any Company data)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now