Solved

convert this xml into csv file

Posted on 2014-03-14
4
86 Views
Last Modified: 2016-04-06
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
Comment
Question by:dipster307
  • 4
4 Comments
 
LVL 23

Expert Comment

by:Jens Fiederer
ID: 39929581
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
 
LVL 23

Expert Comment

by:Jens Fiederer
ID: 39929584
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
 
LVL 23

Accepted Solution

by:
Jens Fiederer earned 500 total points
ID: 39929760
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
 
LVL 23

Expert Comment

by:Jens Fiederer
ID: 39929762
(I filter for Employees.Reference to avoid output of any Company data)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now