Shawn_Moore

CA Clarity Tuesday Tip: Reading a pipe delimited file using GEL

Discussion created by Shawn_Moore Employee on Sep 20, 2011
Latest reply on Sep 21, 2011 by Chris_Hackett
Title: CA Clarity Tuesday Tip: Reading a pipe delimited file using GEL

CA Clarity Tuesday Tip by Shawn Moore, Sr. Principal Support Engineer for 09/20/2011

Our XML Open Gateway Developer's Guide mentions that you can read delimited files using the readFile tag. So how do you read a pipe delimited file? Here are some simple steps on how to write a GEL script to do this.

1) Create a pipe delimited file called, sampledata.pipe, with the following data.

admin|Niku|Administrator|1
testuser|Test|User|5000000
testuser2|Test|User2|5000001


2) Create a file (myfile.xml) using the following GEL code. Note the escaping of the pipe delimiter. (without the backslash, the pipe character is interpreted as "OR", which is what we don't want.)

<gel:script
xmlns:core="jelly:core"
xmlns:file="jelly:com.niku.union.gel.FileTagLibrary"
xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary">
<file:readFile fileName="sampledata.pipe" embedded="false"
var="input" delimiter="\|"/>
<gel:out>Input has ${input.size()} rows.</gel:out>
<core:forEach items="${input.getRows()}" var="row">
<gel:out>Username = ${row[0]}</gel:out>
<gel:out>First = ${row[1]}</gel:out>
<gel:out>Last = ${row[2]}</gel:out>
<gel:out>ResourceID = ${row[3]}</gel:out>
</core:forEach>
</gel:script>


3) Now you can it by running the file created in step 2 (from the directory that xog is installed from or from the bin directory on the app server)

gel -script myfile.xml


F:\niku\12.1.0\install\bin>gel -script myfile.xml
Input has 3 rows.
Username = admin
First = Niku
Last = Administrator
ResourceID = 1
Username = testuser
First = Test
Last = User
ResourceID = 5000000
Username = testuser2
First = Test
Last = User2
ResourceID = 5000001

There it is - the pipe delimited file is read and parsed out!

Enjoy!

-shawn

Outcomes