on 07-18-2015 4:53 PM
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><![CDATA[TextC]]><TextH>
So instead of < and > this characters are getting replaced with < and >
Any solution how can i avoid this transformation of special characters when sending to Target
Thanks in Advance,
Regards,
Pooja
This shouldn't be a prob. Your target system should be able to handle this.
Did you test end-end?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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());
}
}
}
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><<![CDATA[PI is Awesome]]></TextC> ............so to replace the ⁢ and > 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
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("<![CDATA[", "<![CDATA[").replace("]]>", "]]>").getBytes());
} catch (Exception exception) {
getTrace().addDebugMessage(exception.getMessage());
throw new StreamTransformationException(exception.toString());
}
}
}
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
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("<![CDATA[", "<![CDATA[").replace("]]>", "]]>");
outputstream.write(output.getBytes());
} catch (Exception exception) {
getTrace().addDebugMessage(exception.getMessage());
throw new StreamTransformationException(exception.toString());
}
}
}
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
24 | |
11 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.