Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

convert this xml into csv file

Posted on 2014-03-14
4
115 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
2 questions 10 29
How come this regular expression allows "e"? 14 45
JSON  parse help 7 40
Unable to connect C# program to an SQL database - Exception occurs. 4 47
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

809 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