cancel
Showing results for 
Search instead for 
Did you mean: 

CDATA XML Tags - Special Char

Former Member
0 Kudos

Hi Experts,

I am working on interface where in i have to send CDATA XML tag in Target structure, I have checked their are couple of discussions about the requirement but not very helpful for my case.

My Scenario :

Expected :

SOURCE TextH( TextC ) ---------TARGET <TextH> <![CDATA[TextC]]><TextH>

Currently :


SOURCE TextH( TextC ) --------- TARGET <TextH>&lt;![CDATA[TextC]]&gt;<TextH>

So instead of < and > this characters are getting replaced with  &lt;  and &gt;

Any solution how can i avoid this transformation of special characters when sending to Target

Thanks in Advance,

Regards,

Pooja

Accepted Solutions (1)

Accepted Solutions (1)

former_member184720
Active Contributor
0 Kudos

This shouldn't be a prob. Your target system should be able to handle this.

Did you test end-end?

Former Member
0 Kudos

Hi Hareesh,

My target system is FTP server, were i will be dropping the XML file. and the client doesn't want to see the different tags in XML.

I know its should be consumed by Web server , but client don't want to try that. Is their a way i can test this locally to show that this structure can be consumed in web server.

Thanks,

Pooja

RaghuVamseedhar
Active Contributor
0 Kudos

Pooja,

Not well formed XML can be generated using Java mapping.


package com.map; 

import java.io.*; 

import com.sap.aii.mapping.api.*; 

public class Test_JavaMapping extends AbstractTransformation { 

    @Override 

    public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput) throws StreamTransformationException { 

        try { 

            InputStream inputstream = transformationInput.getInputPayload().getInputStream(); 

            OutputStream outputstream = transformationOutput.getOutputPayload().getOutputStream(); 

            // Copy Input content to Output content 

            byte[] b = new byte[inputstream.available()]; 

            inputstream.read(b); 

         

            outputstream.write("<TextH> <![CDATA[".getBytes()); 

            outputstream.write(b); 

            outputstream.write("]]><TextH>".getBytes()); 

        } catch (Exception exception) { 

            getTrace().addDebugMessage(exception.getMessage()); 

            throw new StreamTransformationException(exception.toString()); 

        } 

    } 

Former Member
0 Kudos

hi Raghu,

Thanks for sharing the Code and video, i did used the code to create the java mapping , but i didn't see any transformation with the code.

May be i did something wrong , please correct me,

My scenario again,

I have message mapping , in one of source field it should be mapped  with Target field and get the output with CDATA Tag

Source Filed :  <Text ><PI is Awesome><Text> ------>       Target Field <TextC><![CDATA[PI is Awesome]]></TextC> , so to get this result i wrote simple UDF to get

<[!CDATA]]> tag in target field , but after mapping is executed the output for target field is

<Text > ------>       Target Field <TextC><&lt;![CDATA[PI is Awesome]]&gt;</TextC>  ............so to replace the &it; and &gt; with < and >


and  as you suggested i used the Java mapping in Operation mapping along with Message mapping. But i didn't see any  change. any more suggestion


Thanks in advance,


Regards,

Pooja

RaghuVamseedhar
Active Contributor
0 Kudos

Pooja,

In OM, please use below Java mapping after Message mapping.


package com.map;   

import java.io.*;   

import com.sap.aii.mapping.api.*;   

public class Test_JavaMapping extends AbstractTransformation {   

    @Override   

    public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput) throws StreamTransformationException {   

        try {   

            InputStream inputstream = transformationInput.getInputPayload().getInputStream();   

            OutputStream outputstream = transformationOutput.getOutputPayload().getOutputStream();   

            // Copy Input content to Output content   

            byte[] b = new byte[inputstream.available()];   

            inputstream.read(b);   

                          

            outputstream.write(b.toString().replace("&lt;![CDATA[", "<![CDATA[").replace("]]&gt;", "]]>").getBytes());               

        } catch (Exception exception) {   

            getTrace().addDebugMessage(exception.getMessage());   

            throw new StreamTransformationException(exception.toString());   

        }   

    }   

}   

Former Member
0 Kudos

HI Raghu,

Thank you so much for sharing the code, As advised  created the new jar file with code and imported in PI in OM.

When i am trying to test the message in OM , i am getting an error

Unable to display tree view;Error when parsing an XML document( Content is not allowed in prolog)

with the previous code , i was able to test in OM ,

any suggestions.

Thanks in advance,

Regards,

Pooja

RaghuVamseedhar
Active Contributor
0 Kudos

As XML is not well formed, graphical display is not allowed. Click on below icons OR test the interface end to end.

Former Member
0 Kudos

Hi Raghu,

I tried to Check the src and also downloaded the file, this is what i see

and for end to end test , output is

I even followed this blog and changed the Config , removing SWCV , but no help.

Any suggestions.

Thanks in Advance,

Pooja

RaghuVamseedhar
Active Contributor
0 Kudos

Please try


package com.map;     

import java.io.*;     

import com.sap.aii.mapping.api.*;     

public class Test_JavaMapping extends AbstractTransformation {     

    @Override     

    public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput) throws StreamTransformationException {     

        try {     

            InputStream inputstream = transformationInput.getInputPayload().getInputStream();     

            OutputStream outputstream = transformationOutput.getOutputPayload().getOutputStream();     

            // Copy Input content to Output content     

            byte[] b = new byte[inputstream.available()];     

            inputstream.read(b);     

                            

            String input = new String(b);

            String output = input.replace("&lt;![CDATA[", "<![CDATA[").replace("]]&gt;", "]]>");

            outputstream.write(output.getBytes());                

        } catch (Exception exception) {     

            getTrace().addDebugMessage(exception.getMessage());     

            throw new StreamTransformationException(exception.toString());     

        }     

    }     

}     

Former Member
0 Kudos

Hi Raghu,

Thank you so much for your support , really appreciate it. the latest code worked.

Thanks again.

Pooja

Answers (2)

Answers (2)

Former Member
0 Kudos

Good afternoon dears!

I learned that the CDATA tag has a character limit. This is true? If yes, what is the limit in bytes of the CDATA tag?

Thank's

Former Member
0 Kudos

Hi Pooja,

Try to use the CDATASection on your java mapping.

Example:

import org.w3c.dom.CDATASection;

........

CDATASection textNode = docSaida.createCDATASection(xml);

nodeMessage.appendChild(textNode);

.......

where docSaida is type Document

xml is type String

nodeMessage is a Element

Regards.

Halsen