简体   繁体   中英

Open/close tags are replaced with > <while base64 decoding in SAP PI

I have written a UDF to decode the endcode base64 text in SAP PI mapping. But after decoding the xml tags, open and close tags all are getting replaced by > < > <

Please find below screenshot of the code.

public String Base64Decoder(String EncodedString, Container container) throws StreamTransformationException
{
//Variable to hold decoded string
String decodedString = null;
 byte[] decodedBytes = DatatypeConverter.parseBase64Binary(EncodedString);
try{

//Convert base64 schema to byte array

return new String(decodedBytes,"UTF-8");
//Get the string of decoded byte array


}catch(Exception e) {

}

//Export decoded string
return decodedString;
}

Output after decoding:

<?xml version="1.0" encoding="UTF-8"?>
<ns0:Log xmlns:ns0="http://world.com/pi/M/Log">
<Data>&lt;OUTPUT&gt;&lt;item&gt;&lt;VBELN&gt;0180001027&lt;/VBELN&gt;&lt;WADAT&gt;00000000&lt;/WADAT&gt;&lt;VSTEL&gt;1000&lt;/VSTEL&gt;&lt;KUNNR/&gt;&lt;ITEM&gt;&lt;YITEM&gt;&lt;MATNR&gt;000000000011000082&lt;/MATNR&gt;&lt;LFIMG&gt;1.0&lt;/LFIMG&gt;&lt;MEINS&gt;L&lt;/MEINS&gt;&lt;/YITEM&gt;&lt;/ITEM&gt;&lt;/item&gt;&lt;item&gt;&lt;VBELN&gt;0180001233&lt;/VBELN&gt;&lt;WADAT&gt;00000000&lt;/WADAT&gt;&lt;VSTEL&gt;1000&lt;/VSTEL&gt;&lt;KUNNR/&gt;&lt;ITEM&gt;&lt;YITEM&gt;&lt;MATNR&gt;000000000041000000&lt;/MATNR&gt;&lt;LFIMG&gt;10.0&lt;/LFIMG&gt;&lt;MEINS&gt;LM&lt;/MEINS&gt;&lt;/YITEM&gt;&lt;/ITEM&gt;&lt;/item&gt;&lt;/OUTPUT&gt;</Data>
</ns0:Log>

The data inside <Data> tag is decoded text. But as you can see all its tags are replaced. For example, instead of <OUTPUT> it is printing &lt;OUTPUT&gt;

Can you please let me know what changes should I do in the UDF to avoid this.

Encoded String in Base64:

PE9VVFBVVD48aXRlbT48VkJFTE4+MDE4MDAwMTAyNzwvVkJFTE4+PFdBREFUPjAwMDAwMDAwPC9XQURBVD48VlNURUw+MTAwMDwvVlNURUw+PEtVTk5SLz48SVRFTT48WUlURU0+PE1BVE5SPjAwMDAwMDAwMDAxMTAwMDA4MjwvTUFUTlI+PExGSU1HPjEuMDwvTEZJTUc+PE1FSU5TPkw8L01FSU5TPjwvWUlURU0+PC9JVEVNPjwvaXRlbT48aXRlbT48VkJFTE4+MDE4MDAwMTIzMzwvVkJFTE4+PFdBREFUPjAwMDAwMDAwPC9XQURBVD48VlNURUw+MTAwMDwvVlNURUw+PEtVTk5SLz48SVRFTT48WUlURU0+PE1BVE5SPjAwMDAwMDAwMDA0MTAwMDAwMDwvTUFUTlI+PExGSU1HPjEwLjA8L0xGSU1HPjxNRUlOUz5MTTwvTUVJTlM+PC9ZSVRFTT48L0lURU0+PC9pdGVtPjwvT1VUUFVUPg==

If you say that <Data>&lt;OUTPUT&gt;&lt;... is incorrect only because you see &lt; instead of < inside the XML string, then it's just a misunderstanding from your side.

In XML, the raw character < is always represented &lt; .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM