How to convert fixed-column size files to XML

Get help with installation and running here.

Moderators: DataMystic Support, Moderators, DataMystic Support, Moderators, DataMystic Support, Moderators

Post Reply
Bluemagics
Posts: 1
Joined: Tue May 24, 2005 8:08 pm

How to convert fixed-column size files to XML

Post by Bluemagics »

hi all,

I have some files with fixed column size and want to convert them to XML...
Till know i only found that TextPipe only converts Tab-seperated columns and CVS's to XML...

want make this job a little bit harder is that in some files I need to create sub-elements in my XML...

each line starts with something like this. "#PARENT1 " or "#CHILD01"
so if if have a file with this content:

Code: Select all

#PARENT1 VALUE1 VALUE2  VALUE3 VALUE4
#CHILD01 MYSUBVALUE11 MYSYBVALUE333 MYSYBVALUE3335
#CHILD01 MYSUBVALUE12 MYSYBVALUE343 MYSYBVALUE3332
#PARENT1 VALUE1 VALUE2  VALUE3 VALUE4
#CHILD01 MYSUBVALUE11 MYSYBVALUE333 MYSYBVALUE3335
#PARENT1 VALUE1 VALUE2  VALUE3 VALUE4
#CHILD01 MYSUBVALUE61 MYSYBVALUE334 MYSYBVALUE3333
#CHILD01 MYSUBVALUE52 MYSYBVALUE346 MYSYBVALUE3332
#CHILD01 MYSUBVALUE42 MYSYBVALUE349 MYSYBVALUE3331
I need to convert it to xml and still make the (sub)elements.. can this be done with TextPipe?
User avatar
DataMystic Support
Site Admin
Posts: 2227
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia
Contact:

Post by DataMystic Support »

Just use two simple EasyPattern search/replaces:

Code: Select all

#PARENT1 [ capture(1+ not space), ' ',
     capture(1+ not space), ' ',
     capture(1+ not space), ' ',
     capture(longest 1+ not space or cr or lf) ]
Replace with

Code: Select all

</parent><parent a="$1" b="$2" c="$3" d="$4">
and similarly for CHILD01.

The trick is to close off the previous <parent> tag, either by using an Add Footer filter, or you can also use a EasyPattern match to restrict to

Code: Select all

#PARENT1[ 1+ char, mustEndWith( '#PARENT1' ) ]
and place the other replaces inside it.
Post Reply