-1

I'm trying to generate flat file for test data using JAVA. Flat file has own mapping document which describes all fields of each line.

I was suggested to use XSD for mapping and I did some research on XSD. As I understood that XSD is for only validation of XML. In this case I have to randomly generate XML file based on XSD and convert it to txt or other format. Because as an output I need flat file, not XML.

It seems like using XSD i'm adding extra steps in creating the file as first create XML, validate with XSD and convert it expected format.

What would be your recommendation in my situation for following the mapping document?

Thanks in advance.

H. Pauwelyn
  • 13,575
  • 26
  • 81
  • 144
Alden
  • 11
  • 1
  • 1
    Can you please provide what you have tried, sample data, and sample output? – Andy Jul 28 '16 at 14:48
  • 1
    were you asked to use XSD or XSLT for mapping ? XSD is schema definition that illustrates the organization of an XML , XSLT can map/transform XML to text/xml/html or other formats – Ramachandran.A.G Jul 28 '16 at 14:48
  • 1
    Please learn how to create a [Minimal, Complete, and Verifiable Example](http://stackoverflow.com/help/mcve) – Andrei Zhytkevich Jul 28 '16 at 14:57
  • for now honestly I do not have a clear picture of it. The final output should be flat file with random data on it, but it must be identical to mapping document. For example, first line should contain FirstName(1-10), LastName(11-25), Address(26-50) and every field has its own position, if field has less characters, it should append spaces up to next field. Now i need to make my strategy and plan to start creating it and I'm not sure from what to begin. Thanks. – Alden Jul 28 '16 at 14:58

1 Answers1

1

I have seen your kind of setup before. The reasons may be different than your particular scenario, but nonetheless it made sense. One thing to consider has to do with the skills and tools people have available and so whatever makes the job done quick and well, goes.

You seem to describe an offset based, "flat" data structure. In my case, people used COBOL copybooks which are very good at describing this. IBM Rational Developer had a built-in wizard which allows the creation of Java Data Bindings from a COBOL copybook. This is to say that within a minute one gets a Java class which can create a record for your flat file in no time (it comes with all the logic required to do the padding, etc.)

To get the data generated, there are tools capable of generating XML files which cover all constraints defined by an XSD (e.g. alternate content i.e. xsd:choice, enumerated values, etc.) Now, assuming you have a proper XSD describing your logical model of your flat file, one can get 10s, 100s, even 100K XML generated from an XSD spec. It takes a click, plus the time spent by the tool to create those files.

Next, to get the XML files in your generated Java class, and so avoid going through XSLT or whatever (many shops don't have the skills) it may be as simple as writing Java mapping code between a JAXB generated class and the one created above, or if matching is possible, simply annotate the generated class to support JAXB unmarshalling. This last step may take longer to code, but it would be trivial code any Java developer would know how to do it.

This could possibly give you a view into why someone may have recommended Java and XSD for this task. XSD is a modeling language with built in support for constraints, which may prove helpful in generating test data through combinatorial techniques.

Petru Gardea
  • 21,373
  • 2
  • 50
  • 62