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><OUTPUT><item><VBELN>0180001027</VBELN><WADAT>00000000</WADAT><VSTEL>1000</VSTEL><KUNNR/><ITEM><YITEM><MATNR>000000000011000082</MATNR><LFIMG>1.0</LFIMG><MEINS>L</MEINS></YITEM></ITEM></item><item><VBELN>0180001233</VBELN><WADAT>00000000</WADAT><VSTEL>1000</VSTEL><KUNNR/><ITEM><YITEM><MATNR>000000000041000000</MATNR><LFIMG>10.0</LFIMG><MEINS>LM</MEINS></YITEM></ITEM></item></OUTPUT></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 <OUTPUT>
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><OUTPUT><...
is incorrect only because you see <
instead of <
inside the XML string, then it's just a misunderstanding from your side.
In XML, the raw character <
is always represented <
.
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.