CSV to XML?

Hi

I need to convert a csv file to xml.

Can anyone give me any advice on any approaches.

I read a few articles about this can be done with XSLT but none of these articles covered how you might instantiate this process from within a java method.

What I want to do in my method specifically is:

1. get the CSV file

2. transform to xml (I have a schema - W3C XML schema language)

3. then validate the xml file against my schema

Any advice appreciated?

kind regards

Jon Jackson

[540 byte] By [JonJacksona] at [2007-11-27 5:34:07]
# 1

You can use XSLT to transform an XML file to CSV, but not the other way around.

What you need to do is just read the CSV file, probably using something like http://sourceforge.net/projects/javacsv/ and create your xml file/document from it.

CSV files usually have a first line header of what the columns are named, you could use these header names for creating the element names in your xml document.

So for example this CSV:

"id","name"

1,"foo"

2,"bar"

gets turned into xml:

<document>

<record>

<id>1</id>

<name>foo</name>

</record>

<record>

<id>2</id>

<name>bar</name>

</record>

</document>

cristian.vata at 2007-7-12 15:02:02 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...