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 ]
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?
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.
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.
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.
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.