.csv File to .xml File in VB.Net using 2.0 Framework and .xsd

T

TC

Hey All,

I've been searching for a code snippet, not a 3rd party tool, that takes a
..csv file and transforms it to an .xml file based upon an .xsd.

Can anyone point me in the right direction or provide a code snippet?

I would prefer vb.net but C# is fine too or even pseudo code with
appropriate .Net objects and example.

Thanks,

TC
 
T

TC

Hey Cor,

I know that XSD has nothing to do with .csv ;-)

I meant applying the .xsd to the .xml file that was created from the .csv
file.

I also agree, that I need to go from .csv to dataset and then use the
ability to write the .xml file from there.

Thanks,

TC
 
L

Lloyd Sheen

TC said:
Hey Cor,

I know that XSD has nothing to do with .csv ;-)

I meant applying the .xsd to the .xml file that was created from the .csv
file.

I also agree, that I need to go from .csv to dataset and then use the
ability to write the .xml file from there.

Thanks,

TC

Ok first things first:

Create a dataset from a .csv

1. Create an ODBC datasource to the folder in which your .csv file exists
Open the ODBC Data Source Administrator
Either use User DSN or System DSN (I will use User)
Click Add
In the Select a driver - Select MS Access Text Driver(*.txt, *.csv)
Click Finish
Input a Data Source Name (and description if you want)
Now unclick "Use Current Directory" and use Select Directory to get
directory holding .csv
Go to options. This is where you can select what file extensions will
be used (if no .txt files just cancel)

2. Open VS if not already open
3. View/Server Explorer
4. Right click Data Connection and select Add Connection
5 Change DataSource to MS ODBC Data Source - OK
6. From dropdown of User/System data source choose your new source
created above
7. You now have a Data Connection to your .csv

8. Add New Item to project - Dataset (name it accordingly)
9. Open (click +) on your dataconnection (Server Explorer)
Open tables and you should see your .csv file
10. Drag it to the .xsd designer (if you have column names in the .csv you
will get column names in the dataset)

You now have a dataset which you can use

Hope this helps
Lloyd Sheen
 
S

SurturZ

Just use a filestream and parse the CSV into XML yourself, sheesh. It's not
that hard!


--
David Streeter
Synchrotech Software
Sydney Australia
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top