First, Google for a CSV parsing library and write the piece of code that reads a .csv file into an object hierarchy of your choice. Once you've got this working, move on to writing the XML document. I'd suggest doing it "by hand", meaning that you just get a PrintWriter etc and do writer.println("<?xml version='1.0'?>") and so forth. Finally, you can proceed to validating the resulting XML against a schema. Small steps. That's all it takes.
Originally posted by Lasse Koskela: First, Google for a CSV parsing library and write the piece of code that reads a .csv file into an object hierarchy of your choice.
I kind of like mine, located just a bit down the page under Code and Utilities. -Jeff-
Originally posted by Jeff Langr: I kind of like mine, located just a bit down the page under Code and Utilities.
Heh. I've got one also. I guess every other Java developer does
Krishna Radha
Greenhorn
Joined: Aug 30, 2001
Posts: 25
posted
0
Once you've got this working, move on to writing the XML document. I'd suggest doing it "by hand", meaning that you just get a PrintWriter etc and do writer.println("<?xml version='1.0'?>") and so forth.
Is there any better solution that doing it "by hand".. ? Maybe once we read the CSV file using the CSV parsing utility, if we have an existing xsd, just create objects of this xsd and fill that up and serialize to get the xml.
If anyone has any better solutions on how to convert CSV to XML, please suggest.
Thanks
Lasse Koskela
author
Sheriff
Joined: Jan 23, 2002
Posts: 11962
5
posted
0
You could also just create a DOM tree and serialize that. It should be a lot easier than generating Java code from an XML Schema document, etc.
Krishna Radha
Greenhorn
Joined: Aug 30, 2001
Posts: 25
posted
0
Instead of explicitly populating the XML ourselves, are there any packages available to do that?
Can we use XSLT to specify template for conversion of CSV to XML? I see XSLT being used from XML to CSV.. Can we use the other way as well?
If so, how can this be done?
Lasse Koskela
author
Sheriff
Joined: Jan 23, 2002
Posts: 11962
5
posted
0
Originally posted by Krishna Radha: Can we use XSLT to specify template for conversion of CSV to XML? I see XSLT being used from XML to CSV.. Can we use the other way as well?
Unfortunately XSL is only applicable for processing well-formed XML documents.
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12266
1
posted
0
Instead of explicitly populating the XML ourselves, are there any packages available to do that?
I suppose you could create a class following JavaBean conventions to hold the CSV data items and then use java.beans.XMLEncoder to write XML. That would probably only work for simple data. Bill
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.