cancel
Showing results for 
Search instead for 
Did you mean: 

Count lines of xml file

Former Member
0 Kudos

hi

i have flat file -> idoc scenario and I want to use mapping/cr8 user-defined function to count ALL the lines of the xml file

I tried to use index function with remove context and split by value and it didnt help ( mayb i did it wrong )

if i use count function i have to use it on EACH line and add all

the flat file MT is

Integral_MT

___________IDOC

__________________H_Line (1)

__________________L_Line (unbounded)

__________________V_Line (unbounded)

any suggestions?

thx

Shai

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

You can use user defined function. Handle the context. just return the length.

Regards,

Kavita

Former Member
0 Kudos

i didnt succced writing that function

can u try giving example ?

Shabarish_Nair
Active Contributor
0 Kudos

put the context to the parent node (maybe the MT itself), then use a UDF like

public void RecordCount(String[] a, .....)

{

tempCount = a.length;

........

}

for each node once you get the count pass them to a add function or create onto handle the add with the number of inputs (the count functions) and return the total number of count.

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

You just need to write one liner code in function.

result.addValue(Integer.toString(a.length));

and change context to root.

-Kavita

Former Member
0 Kudos

still doesnt work

i did remove context on the line and then used this functions and it returns java error

Shabarish_Nair
Active Contributor
0 Kudos

put the context to the top most parent.

Create the UDF with 'context' and return a.length !!

That will give you the count.

Also try posting the java error here ... and your code too ..

Shabarish_Nair
Active Contributor
0 Kudos

the flat file MT is

Integral_MT

___________IDOC

__________________H_Line (1)

__________________L_Line (unbounded)

__________________V_Line (unbounded)

Your UDF sud look like

public void count(String[] a,ResultList result,Container container){

//write your code here

int i = 0;

i = a.length;

String val = String.valueOf(i);

result.addValue(val);

}

and the context for

IDOC

H_Line (1)

L_Line (unbounded)

V_Line (unbounded) sud all be Integral_MT

Former Member
0 Kudos

what is the diffrence between value,context,and queue user functions?

now it works with on each line

I want a function that gets three parameters a,b,c

(h line,g line,v line) and counts them all

and to remove the context of each one in the function

Shabarish_Nair
Active Contributor
0 Kudos

public void count(String[] a, String[] b, String[] c, ResultList result,Container container)

{

//write your code here

int i = 0;

int j = 0;

int k = 0;

i = a.length;

j = b.length;

k = c.length;

i = ijk;

String val = String.valueOf(i);

result.addValue(val);

}

and all the context will be the root.