aspose file tools*
The moose likes XML and Related Technologies and the fly likes XMl to flatfile conversion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XMl to flatfile conversion" Watch "XMl to flatfile conversion" New topic
Author

XMl to flatfile conversion

Sudhakar Rao
Ranch Hand

Joined: May 21, 2005
Posts: 36
Hi,
Can any body give java code snippet for converting XML file to flat file.
regards
Sudhakar
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39548
    
  27
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?


Ping & DNS - updated with new look and Ping home screen widget
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18127
    
    8

And why Java? For this task I would consider using XSLT.
Sudhakar Rao
Ranch Hand

Joined: May 21, 2005
Posts: 36
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
Bartender

Joined: Oct 14, 2005
Posts: 18127
    
    8

In that case it's a simple XSLT and I would definitely use that.
Sudhakar Rao
Ranch Hand

Joined: May 21, 2005
Posts: 36
Can I have sample code for XSLT also. I want to store the flat file in unix system.
Thanks in Advance
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39548
    
  27
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XMl to flatfile conversion
 
Similar Threads
How to do XML to DB using Message Driven Bean?
Annotation in spring
XSD
Content is not allowed in prolog (EDIT: emergency code fix help!)
Convert XSD to XML