Discussions

XML & Web services: Convert mainframe flat-file (fixed-width) to valid XML file

  1. Hi all,
      I am from mainframe background and have recently been introduced to XML/Java technologies. Currently I am in a project where I need to convert a fixed-width flat file residing on z/OS mainframe to valid XML file. I've already got the XML Schema. I've got following questions:

    1. How can I achieve the conversion?
    2. What validator can I use or is recommended?
    3. Can the whole conversion to validation process be automated so as to run without any manual intervention on a periodic basis?

    Any help would be appreciated.

    Thanks.
  2. Hi,

    I personally don't know of any tool that would do that "automagically" for you. BEA's WLI has some really nice features designed specifically for transformation of data from virtually any format to XML, but I guess you're not using WLI.

    Without WLI, here's how I would do it:
    - Create a schema describing your target XML domain
    - Parse the file line by line. This should be really easy since you already know the fixed width format.
    - Use DOM if the data isn't large or if memory is not a concern.
    - Use SAX otherwise
    - OR, you can use XMLBeans or Castor to deal with your XML document as a Java object (I actually prefer this).

    About scheduling (again WLI event generators come in handy) but with no WLI, you can have your java process watch for the file and consume it as it arrives.

    I hope I shed some light on the possibilities for you. I'm sure other people could have very different approaches :-)
  3. Hi Ahmed,
      Thanks for the reply. It does shed some light on the possibilities that are available around. Some more questions here (I know thaty may sound daft to an experienced XML user but nonetheless will help me understand technology better!):

    - Create a schema describing your target XML domain
    Q: What do you mean by XML domain? As I already have a schema, could I perhaps use it in anyway to write a SAX/DOM program as suggested by you?

    - Use DOM if the data isn't large or if memory is not a concern.
    Q: As the PCs are woefully short of RAM (only 256Mb on the top PC!) so I guess that DOM can be ruled out. Right?

    - Use SAX otherwise
    Q: Plz suggest some piece of coding as that'll help me get started.

    - OR, you can use XMLBeans or Castor to deal with your XML document as a Java object (I actually prefer this).
    Q: An example usage would indeed be much appreciated and be very helpful, please.
  4. BR,
    Sorry for the delay, I don't read SS everyday :-)

    About your questions:
    Q - What do you mean by XML domain? As I already have a schema, could I perhaps use it in anyway to write a SAX/DOM program as suggested by you?

    A - I apologies for using such a confusing word "Domain". What I basically meant is your XML "data structure(s)". I don't know of a tool that would generate a SAX parser class for you, and DOM deals with instances of documents

    Q - As the PCs are woefully short of RAM (only 256Mb on the top PC!) so I guess that DOM can be ruled out. Right?

    A - I believe so (but if your document is small enough then this shouldn't be a problem)

    Q-Plz suggest some piece of coding as that'll help me get started.


    A- a quick Google search yields some interesting sites among them was this one (just a sample). I search for "SAX Parsing Example" http://www.troobloo.com/tech/sax.shtml

    Q - An example usage would indeed be much appreciated and be very helpful, please. (Castor, XMLBeans)

    A - Basically, Castor and XMLBeans take an XML schema and generates Java classes for you that can read and write the type of document the schema refers to. This is the best approach cause you deal with the document as a pure java class using setXX and getXX functions. refer to http://castor.exolab.org/ and http://dev2dev.bea.com/technologies/xmlbeans/index.jsp..

    Let me know if you have any other questions.

    Cheers,
    AT