This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Transforming a flat file to XML file

 
Sai Prasad
Ranch Hand
Posts: 560
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 560
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 560
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic