cancel
Showing results for 
Search instead for 
Did you mean: 

Java Mapping remove xsi:nil='true' from payload

0 Kudos

Hello all,

I am a new in PI, there need to remove character xsi:nil='true'.

I tried to use Graphic mapping and XSLT mapping for this. However, these two methods need to verify the validity of the XML file first.

Below are xml structure, could someone help this?

Many thanks in advance,

Br,

Nero.

<ns1:ConnectException
xmlns:ns1='http://test.com/connect/_2007_08/'>


    <ns2:errorCode
xmlns:ns2='http://test.com/services/exception/_2006_12_15/exception'>POL33F2060</ns2:errorCode>


    <ns3:errorDescription
xmlns:ns3='http://test.com/services/exception/_2006_12_15/exception'>User
ID ZZJ12FJ81 is not authorised for policy 31444</ns3:errorDescription>


   
<ns4:serverErrorReferenceToken
xmlns:ns4='http://test.com/services/exception/_2006_12_15/exception' xsi:nil='true'/>


   
<ns5:values
xmlns:ns5='http://test.com/services/exception/_2006_12_15/exception'>


        <ns5:value>ZZJFJ814</ns5:value>


       
<ns5:value>314635</ns5:value>


   
</ns5:values>


</ns1:ConnectException>

Accepted Solutions (1)

Accepted Solutions (1)

former_member190293
Active Contributor
0 Kudos

Hi Nero!

Read input payload as text with java mapping and replace "xsi:nil" with empty string.

Regards, Evgeniy.

Answers (1)

Answers (1)

sugata_bagchi2
Active Contributor
0 Kudos

Hi Nero,

Why do you want to remove that? you can request the source system owner to provide the XSD and handle the xsi:nil .

If you want to remove xsi:nil from the element, you can use boolean function "isNil" and an "if" statement to pass an empty constant-

Thanks

Sugata

0 Kudos
public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput) throws StreamTransformationException {
         try {
             InputStream inputstream = transformationInput.getInputPayload().getInputStream();
             OutputStream outputstream = transformationOutput.getOutputPayload().getOutputStream();
             // a) Copy Input content to String
             byte[] b = new byte[inputstream.available()];
             inputstream.read(b);
             String inputContent = new String(b);
            
             inputContent = inputContent.replaceAll("<?xml version= \"1.0\" encoding= \"UTF-8\" ?>", "");
          
             outputstream.write(inputContent.getBytes());
         } catch (Exception exception) {
             getTrace().addDebugMessage(exception.getMessage());
             throw new StreamTransformationException(exception.toString());
         }
     }