Sign In | Register Now About Bytes | Help | Site Map
Connecting Tech Pros Worldwide

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

Question posted by: TC (Guest) on June 27th, 2008 07:20 PM
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


Cor Ligthert[MVP]'s Avatar
Cor Ligthert[MVP]
Guest
n/a Posts
June 27th, 2008
07:20 PM
#2

Re: .csv File to .xml File in VB.Net using 2.0 Framework and .xsd
TC,

A CSV has no XSD, and there is not even a relatieon, how did you want to do
this, without a XSD it is simple,

http://www.vb-tips.com/dbpages.aspx?Search=csv

To make it an xml file you do simple

ds.WriteXML(path)

Cor


"TC" <getmyemails2@yahoo.comschreef in bericht
news:%23GRmCZirIHA.1872@TK2MSFTNGP04.phx.gbl...
Quote:
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
>



TC's Avatar
TC
Guest
n/a Posts
June 27th, 2008
07:20 PM
#3

Re: .csv File to .xml File in VB.Net using 2.0 Framework and .xsd
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


"Cor Ligthert[MVP]" <notmyfirstname@planet.nlwrote in message
news:FA435949-0DB1-4A02-9E7D-54773230DFA4@microsoft.com...
Quote:
TC,
>
A CSV has no XSD, and there is not even a relatieon, how did you want to
do this, without a XSD it is simple,
>
http://www.vb-tips.com/dbpages.aspx?Search=csv
>
To make it an xml file you do simple
>
ds.WriteXML(path)
>
Cor
>
>
"TC" <getmyemails2@yahoo.comschreef in bericht
news:%23GRmCZirIHA.1872@TK2MSFTNGP04.phx.gbl...
Quote:
>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
>>

>




Lloyd Sheen's Avatar
Lloyd Sheen
Guest
n/a Posts
June 27th, 2008
07:20 PM
#4

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

"TC" <getmyemails2@yahoo.comwrote in message
news:OAu7byrrIHA.3804@TK2MSFTNGP02.phx.gbl...
Quote:
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
>
>
"Cor Ligthert[MVP]" <notmyfirstname@planet.nlwrote in message
news:FA435949-0DB1-4A02-9E7D-54773230DFA4@microsoft.com...
Quote:
>TC,
>>
>A CSV has no XSD, and there is not even a relatieon, how did you want to
>do this, without a XSD it is simple,
>>
>http://www.vb-tips.com/dbpages.aspx?Search=csv
>>
>To make it an xml file you do simple
>>
>ds.WriteXML(path)
>>
>Cor
>>
>>
>"TC" <getmyemails2@yahoo.comschreef in bericht
>news:%23GRmCZirIHA.1872@TK2MSFTNGP04.phx.gbl...
Quote:
>>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
>>>

>>

>
>


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


=?Utf-8?B?U3VydHVyWg==?='s Avatar
=?Utf-8?B?U3VydHVyWg==?=
Guest
n/a Posts
June 27th, 2008
07:20 PM
#5

Re: .csv File to .xml File in VB.Net using 2.0 Framework and .xsd
Just use a filestream and parse the CSV into XML yourself, sheesh. It's not
that hard!


--
David Streeter
Synchrotech Software
Sydney Australia


"Lloyd Sheen" wrote:
Quote:
>
"TC" <getmyemails2@yahoo.comwrote in message
news:OAu7byrrIHA.3804@TK2MSFTNGP02.phx.gbl...
Quote:
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


"Cor Ligthert[MVP]" <notmyfirstname@planet.nlwrote in message
news:FA435949-0DB1-4A02-9E7D-54773230DFA4@microsoft.com...
Quote:
TC,
>
A CSV has no XSD, and there is not even a relatieon, how did you want to
do this, without a XSD it is simple,
>
http://www.vb-tips.com/dbpages.aspx?Search=csv
>
To make it an xml file you do simple
>
ds.WriteXML(path)
>
Cor
>
>
"TC" <getmyemails2@yahoo.comschreef in bericht
news:%23GRmCZirIHA.1872@TK2MSFTNGP04.phx.gbl...
>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
>>
>



>
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
>
>


 
Not the answer you were looking for? Post your question . . .
189,172 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
  • Didn't find the answer you were looking for?
    Post Your Question
  • Top Community Contributors