wood burning stoves 2.0*
The moose likes XML and Related Technologies and the fly likes Transforming a flat file to XML file 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 "Transforming a flat file to XML file" Watch "Transforming a flat file to XML file" New topic
Author

Transforming a flat file to XML file

Sai Prasad
Ranch Hand

Joined: Feb 25, 2002
Posts: 560
I am new to XML and I am trying to read a flat file in Java and create an xml file. I like to know what are the possible ways to accomplish this on the server side. Thanks a lot.
Also the the conversion is not straight forward. Based on some values, xml elements need to added or ignored.
[ September 17, 2003: Message edited by: Sai Prasad ]
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
Wow, that's a really loaded question. I think you may need to give us a bit more info to help you solve your problem. What does the flat file represent? Is the data translated to objects in your system, or a database? Are you wanting to deal with just Strings?
Sai Prasad
Ranch Hand

Joined: Feb 25, 2002
Posts: 560
Thanks Jason. I get a file from main frame which has fixed length elements in each line. Each file contains information about an invoice. I need to convert this file to a specific xml format and send that file to another group.
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
Has the other group provided an XSD (schema) or DTD to define how they expect the XML to look? Since they will be ingesting it, I assume they will determine how the XML will look. That will drive what you need to do with your flat files.
Sai Prasad
Ranch Hand

Joined: Feb 25, 2002
Posts: 560
Jason, Thanks. I haven't received it yet. This project is in the very early stage. Let us assume that I get a xsd or dtd, how should I program to convert the flat file to XML? I have been reading about DOM and SAX parsers.
Also this application will be executed in a weblogic environment.
Tom Blough
Ranch Hand

Joined: Jul 31, 2003
Posts: 263
You might consider using JDBC/ODBC to treat the flatfile as a database and start from there. That would save a lot of parsing work.


Tom Blough<br /> <blockquote><font size="1" face="Verdana, Arial">quote:</font><hr>Cum catapultae proscriptae erunt tum soli proscripti catapultas habebunt.<hr></blockquote>
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
Well, depending on the data, I would most likely read in the file and convert each line, if it makes sense, into a data object holding the values.
Create a collection of those guys, then pass it to the class that handles writing out the collection to XML using a DOMParser. That way, if you need to manipulate the data at some point or do some sort of logic on the collection, you can do so before writing to XML.
How you actually write the objects to XML depends on the schema/dtd, and what the requirements are.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Transforming a flat file to XML file
 
Similar Threads
problem with "group by"
generate XML from a flat file using SAX ?
Hibernate reporting
Tool for converting Flat file to HTML
XML for exchanging data