Log out?

Exercise 3 – XML to Fixed-Width File

Start up the EIConsole as usual, and create a directory listener for the XML document XMLInput. This process can be a little more frustrating – you need to do some transformations before you begin. At present the flat-text parser only supports one unbound record – which means you need to create multiple targets if your XML file contains multiple unbound records. Some basic rules for utilizing the flat-text parser – remember that flat text is not as dynamic as XML as a target. You will likely lose significant portions of your formatting in the process of producing it. Now, with that in mind, you will need to transform your XML data to fit the following schematic:

<data>
        <record>
                <field />
                <field />
                <field />
                etc
        <record>

<data>

You can have additional data, but it always needs to follow that basic layout, and always needs to be well-structured; i/e, all data included in a single all-inclusive tag. (data, in this case.) Data structured this way won’t be read:

<data>
        <field />
        <field />
        <field />

<data>

It needs an inclusive non-base record tag to hold the data fields. You can read in as many bound data items – that is, records with a pre-specified number of entries – as you want, but only one unbound – i/e, records with an unlimited potential number of entries. The same goes for fields within records – only one, the last, may be unbound. To produce the text, open up the Delimited and Fixed-Width File transformation module on your output – create a test item. We’re producing a Fixed-Width file, but we want returns separating each record, so select Other when it prompts you which kind you want. Record should be Delimated – leave the delimiter as n, this is the escape character for a line return – and set Field Style as Fixed Width. (You could make it tabbed if you’d rather – in which case, leave the field style as delimited, and the field delimiter as t, the escape character for a tab.) Now, look at your properly formatted XML:

<data>
        <record>
                <field />
                <field />
                <field />
                etc
        <record>

<data>

In the record structure tab, create a Record called – whatever your XML document uses as record. It uses this to read from the XML structure, so make sure the names are correctly formatted. Create fields with similar naming restrictions. If you are creating a fixed-width document, make sure to set the starting character and width fields to appropriate values. It should output correctly once you’ve established the format. You can reorder the fields – it isn’t order-sensitive. Null fields will output blank. Fields you haven’t established a format for won’t appear in the output at all. If you have multiple unbound records you want to output to the same file, you can create a new target, using the same source directory and filename, and utilize the “append to file” checkbox. It will output to the end of the same file. If you have multiple unbound fields, or your data otherwise doesn’t fit the format shown above, restructure your target XML in the XSLT configuration on the target Transform box. You can also do this in source Transform, but you may have different desired formattings for different targets, if, for example, you have multiple unbound records, or if you have another target format in mind; since this transform is specific to this target, it is adviseable to do it in target transform, as it will reduce the transformational coupling, and hence the amount of work you will need to do in modifying the route if a new target becomes necessary in the future.

    to post comments

    This is a unique website which will require a more modern browser to work! Please upgrade today!

    Thanks!

    Our editors are notified.

    Close