cancel
Showing results for 
Search instead for 
Did you mean: 

UDF - how to split XML string in target XML

former_member440449
Participant
0 Kudos

Hi Gurus,

My issue is simple but per my poor Java knowledge I am not able to work on this.

I have this structure as string:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns2:VFMDesSendRemitoResponse xmlns:ns2="http://ws.monsanto.verifarma.bdev.com.ar/">

<return>

<codOperac>41</codOperac>

<errors>

<description>el valor 30-00000000-7 para el campo cuit dest es invalido.</description>

<errorCode>-11</errorCode>

</errors>

<errors>

<description>el valor 30-00000000-7 para el campo cuit ship es invalido.</description>

<errorCode>-11</errorCode>

</errors>

<errors>

<description>el campo almacen no puede estar vacio</description>

<errorCode>-18</errorCode>

</errors>

<errors>

<description>la fecha 20140206 posee un valor invalido. Formato valido: yyyy-MM-dd</description>

<errorCode>-19</errorCode>

</errors>

<errors>

<description>la fecha 20140206 posee un valor invalido. Formato valido: yyyy-MM-dd</description>

<errorCode>-19</errorCode>

</errors>

<errors>

<description>el valor 1122 - null para el campo dep?sito es invalido.</description>

<errorCode>-11</errorCode>

</errors>

<status>ERR</status></return>

</ns2:VFMDesSendRemitoResponse></soap:Body></soap:Envelope>

And I want to split it into next structure:

<errors> (0..unbounded)

<description> (0..1)

</description>

<errorCode> (0..1)

</errorCode>

</errors>

I have an old UDF with this code:

String empty = "<" + tag[0] + "/>";

String begin = "<" + tag[0] + ">";

String end = "</" + tag[0] + ">";

String data = input[0];

do {

                              int i = data.indexOf(tag[0]);

                              if (i < 1) break; else i--;

                              if (data.substring(i, i+empty.length()).equals(empty)) {

    result.addValue(""); //empty

    data = data.substring(i+empty.length());

                              }

                            else {

    data = data.substring(i+begin.length());

    int endIndex = data.indexOf(end);

    result.addValue(data.substring(0, endIndex));

    data = data.substring(endIndex + end.length());

                              }

} while (data.length() > empty.length());

But it is only sending data for the first "errors" segment created and all the others are dismissed.

Is anyone able to help me correcting this code to send data to ALL errors segments?

Thanks!

Accepted Solutions (1)

Accepted Solutions (1)

former_member184720
Active Contributor
0 Kudos

You said input is just a string but your UDF needs two inputs

Also i see that you are using only the first occurence data[0] &tag[0] then why don't you use simple UDF?

Change the execution type to single values and instead of result.addValue() you should simply use return ;

However please provide in the input strings you are passing to udf so that we can suggest..

------------

Can you confirm is that your input payload or you are getting this xml as part of one string?

If it is your input structure then i don't think you need such a complex UDF...

Message was edited by: Hareesh Gampa

former_member440449
Participant
0 Kudos

Hi Hareesh,

I am receiving the whole string frm a SOAP Lookup UDF.

Sorry I was not clear but for the <errors> tab I have this code working successful:

String findStr = "<errors>";

int lastIndex = 0;

int count =0;

while(lastIndex != -1){

lastIndex = input[0].indexOf(findStr,lastIndex);

if( lastIndex != -1){

result.addValue("");

lastIndex+=findStr.length();

}

}

I am using all values of a queue and I have 1 argument (input as String) and 1 Result (result as ResultList).

For the UDF mentioned in my first post, the second value I am getting belongs to the fieldname itself (which is either for description as for errorCode).

former_member184720
Active Contributor
0 Kudos

Hi Claudio - I just tested your other UDF by passing your soaplookup string as first parameter and  "description" as second paramter. and i see the value are being split properly.

I think you just need to use splitby(for each value) after the UDF.

former_member440449
Participant
0 Kudos

Sometimes I feel so dummy

Thank you Hareesh!

Answers (1)

Answers (1)

Harish
Active Contributor
0 Kudos

Hi Claudio,

Your UDF is queue or context udf? Please change it to context UDF.

Please change the input field context to one level up or use remove context function for input field.

also provide the display queue screenshot to give exact inputs.

regards,

Harish