Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Want to convert xml to csv format

 
akshay pandit
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello to all !! I want to convert an xml file to csv format.Can any one help me ..
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you want to turn the elements of the XML into CSV in the same order or do you need to manipulate the data first?
Have you read any Java and XML tutorials? Bought a book?
Bill
 
Joel H. Amoussou
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
XSLT can be used to tramsform XML to CSV. For an example, check "XML Databases" (published by Wrox), chapter 12.
----
Joel Amoussou
IBM XML Certification Practice Test
http://www.xmlmentor.net/xmlexamsim.htm
 
akshay pandit
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all thanks for the reply...
I have read the xml file using sax parser and want to save the all the read elements/attributes & values and characters in csv format..
Suggestions will be a great help
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want all the contents with various bits separated by commas, just write to an output file from every startElement and characters method. In order to get the commas in the right place you will have to pay attention to the nesting of elements.
On the other hand if you are trying to prepare data for interpretation in Excel, you need to think about what you want the resulting spreadsheet to look like.
Bill
 
Suresh Kanagalingam
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out apache web site for Xalan samples (http://xml.apache.org/xalan-j/index.html). This site has good samples showing how to convert XML into structured text format. You can change sample code to get your CSV format.
Good luck
Suresh
 
akshay pandit
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
thanks for the solution..
It really helped me a lot..
can u please let me know if we want to do a backward engineering like in our case if we want to transform csv back to xml and xls back to xml then
what can be done...?
Once again thanks for the reply...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic