Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XMl to flatfile conversion

 
Sudhakar Rao
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Can any body give java code snippet for converting XML file to flat file.
regards
Sudhakar
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
XML describes structured data. You need to decide how to convert structured data into "flat" data before anyone (and that person will be you, although we'll try to help) can write the code to do it. So: how does the XML look like, and how would it look in a non-XML text file?
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And why Java? For this task I would consider using XSLT.
 
Sudhakar Rao
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The XML file looks like
<contacts>

<contact>
<name>sudhakar</name>
<email>dvvn_sudha@yahoo.com</email>
<phone>21843949</phone>
<contact>

<contact>
<name>javaking</name>
<phone>383939</phone>
</contact>

</contacts>

The converted flat file would look like this

[contacts]

[contact]
name=sudhakar email=dvvn_sudha@yahoo.com phone=21843949

name=javaking phone=383939

The requirement here is take the xml file as input and using xslt and java generate output file as flatfile.
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In that case it's a simple XSLT and I would definitely use that.
 
Sudhakar Rao
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can I have sample code for XSLT also. I want to store the flat file in unix system.
Thanks in Advance
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We don't like to give out ready-made solutions; it deprives people of the opportunity to learn. But we'll gladly try to help someone arrive at a solution; what do you have so far
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic