Reputation: 45
I have a fixed width text file to convert to XML. Can you tell me how to make it in detail?
My sample text looks like this...
9621120080828200808290001084713CENTRAL TIONG NAM WAREHOUSE 086014286100501330071881000020000000000000090002PC 20.000 20.000 81E0 600.000 20.000 PC UB
9621120080828200808290001084713CENTRAL TIONG NAM WAREHOUSE 086014286100501330071881900001000000000000011131PC 1000.000 24000.000 8100 13680.000 1920.000 47/2008 CRTUB 00100000000003346495
from the first line I want to convert text file based on length..
1st 5 characters to File No
i.e 96211
next 8 chars to Shipment Creation Date
i.e 20080828
next 8 chars to Delivery Date
i.e 20080829
and so on...
Note : first two lines is considered as one record.....
I want the output like below
<FileNo>96211<FileNo>
<ShipmentCreationDate>20080828<ShipmentCreationDate>
<DeliveryDate>20080829<DeliveryDate>
Thanks in advance!
Upvotes: 3
Views: 2284
Reputation: 628
If you have no control over the outputting Application you will have to write a converter tool.
Take your preferend language and matching XML-Lib and write a small application which parses the data and writes it as XML.
Upvotes: 0
Reputation: 754993
I would urge you to have a look at the FileHelpers library.
It's a C# library that allows you to import fixed-width or delimited files into C# very quickly.
You can then easily turn around and spit out those records as XML from your C# - no problem at all!
In detail:
XmlSerializer
, you can then easily serialize those objects back out to XMLShould be about 50 lines or less of code :-)
Upvotes: 4