Solved

convert this xml into csv file

Posted on 2014-03-14
4
62 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
(I filter for Employees.Reference to avoid output of any Company data)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

763 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

11 Experts available now in Live!

Get 1:1 Help Now