473,387 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

conversion table from csv to xml

1
hello
I am beginner in developing C # and I will like to develop an application that a converte. csv file (table) in an xml file
Jul 9 '12 #1
1 2125
PsychoCoder
465 Expert Mod 256MB
You can use the XElement within LINQ to accomplish this. Here's a sample of what I'm talking about:

Expand|Select|Wrap|Line Numbers
  1. public XElement GetCustomers()
  2. {
  3.     string[] csvFile = File.ReadAllLines("sample.csv");
  4.     var customer = new XElement("Root",
  5.                                         from @string in csvFile
  6.                                         let fields = @string.Split(',')
  7.                                         select new XElement("Customers",
  8.                                             new XAttribute("CustomerID", fields[0]),
  9.                                             new XElement("CompanyName", fields[1]),
  10.                                             new XElement("ContactName", fields[2]),
  11.                                             new XElement("ContactTitle", fields[3]),
  12.                                             new XElement("Phone", fields[4])));
  13.     return customer;
  14. }
Hope that helps

NOTE: My sample csv file was comma delimited. If you're is a different character then split on your delimiter.
Jul 9 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: plopez | last post by:
Hi I'm a bit of a noob to xslt. I have a data.xml document like this.. input.xml <energy> ..lots and lots of other data..... <units>(Watts)<\units> <value>1000.0<\value> </energy>
2
by: Andy | last post by:
Hi... i'm trying to understand the concept of function name overloading in c++. to understand the resolving system it's important to understand the diffrent levels of typecasting (exact match,...
1
by: Vladimir Khvostov | last post by:
Hi, We have some DB2 table on the host that has varchar(3200) columns that are used to store binary data (I know that "varchar(3200) for bit data" should have been used, by modifying host table is...
6
by: Pawel Janik | last post by:
Hello.. I have some static functions, that do somple conversion. But to do this conversion, I have to use some conversion tables. And now the question: how to fill this conversion tables (the...
0
by: timnels | last post by:
I've got a bizzare issue where I have an XML file to load into a data set like: <conversion> <table name="parent"> <table name="child"> </table> </table> <table name="another parent"> ....
0
by: Jm | last post by:
Hi All I recently got some help with code conversion that i used in vb6 to block a specific tcp port. The code runs under a timer and is run on a very low tick count (Meaning it happens...
3
by: das | last post by:
Hello all, Can someone help me with this SQL? 1) EMPLOYEE table has columns 'employee_id' and 'emp_sid' and other columns 2) EMPLOYEE_BENEFITS table has a column called employee_entity, this...
0
by: Lou Evart | last post by:
DOCUMENT CONVERSION SERVICES Softline International (SII) operates one of the industry's largest document and data conversion service bureaus. In the past year, SII converted over a million...
0
by: =?Utf-8?B?RGVuaXMgU29oZXQ=?= | last post by:
Hi all, I've created a new project to test ObjectDataSource component. I've just added a new objectdatasource, configured it (linked to a table) etc ... It works fine on localhost, i can...
0
by: maheshmohta | last post by:
Background Often while remodeling legacy application, one of the important tasks for the architects is to have an optimum usage of storage capabilities of database. Most of the legacy applications...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.