I've tried to follow examples in other posts but they have issues. This seems like something that should have a straight forward solution. I use a web service that returns a <DATA> node that contains CDATA that interns contains the XML payload I need. I've managed to write the java mapping to strip out the <DATA> and the CDATA and it looks fine when I test it in the OM test tab. But when I run this through PI the XML inside the CDATA is all escaped and everything I do to use it throws errors. I seriously need to get this working and could use any help. Here is a sample of the XML...
<?xml version="1.0" encoding="UTF-8"?>
<ns0:MT_ExportPayload xmlns:ns0="http://isbdcapp86/Enablon7.8Train/rpc_literal.wsdl">
<Data><![CDATA[<?xml version="1.0" encoding="UTF-16" standalone="yes" ?>
<Document>
<Record>
<EmployeeID>ID000006150265</EmployeeID>
<ApplicationUser><None></ApplicationUser>
<LastName>Shi</LastName>
<FirstName>Nansun</FirstName>
</Record>
</Document>]]>
</Data>
</ns0:MT_ExportPayload>
OM Test Tab using my java map (code below) gives me this...
<Data>
<Document>
<Record>
<EmployeeID>ID000006150265</EmployeeID>
<ApplicationUser><None></ApplicationUser>
<LastName>Shi</LastName>
<FirstName>Nansun</FirstName>
</Record>
</Document>
</Data>
But when I look at logs (soap message logs), I see this note the XML preamble in the <DATA> and even my needed xml is escaped...
<enab:ExportDataResponse xmlns:enab="enablon"> <Data><?xml version="1.0" encoding="UTF-16" standalone="yes" ?>
<Document>
<Record>
<EmployeeID>ID000006150265</EmployeeID>
<ApplicationUser>&lt;None&gt;</ApplicationUser>
<LastName>Shi</LastName>
<FirstName>Nansun</FirstName>
</Record>
</Document></Data>
</enab:ExportDataResponse>
The Java map based on what I have found in other, somewhat old posts...
import org.w3c.*;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import com.sap.aii.mapping.api.*;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
public class GetEnablonPayload2 extends AbstractTransformation {
public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput) throws StreamTransformationException {
try {
InputStream in = transformationInput.getInputPayload().getInputStream();
OutputStream out = transformationOutput.getOutputPayload().getOutputStream();
// Copy Input content to Output content
byte[] b = new byte[in.available()];
in.read(b);
DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
DocumentBuilder builderel=factory.newDocumentBuilder();
Document docIn=builderel.parse(new ByteArrayInputStream(b));
Document docOut = null;
docOut=builderel.newDocument();
Node node;
NodeList nListRec = docIn.getElementsByTagName("Data");
node = nListRec.item(0);
Node clon = docOut.importNode(node,true);
docOut.appendChild(clon);
String sResult = null;
sResult = convertDocument_String(docOut);
sResult = sResult.replace("<![CDATA[<?xml version=\"1.0\" encoding=\"UTF-16\" standalone=\"yes\" ?>","");
sResult = sResult.replace("]]>","");
out.write(sResult.getBytes());
} catch (Exception exception) {
getTrace().addDebugMessage(exception.getMessage());
throw new StreamTransformationException(exception.toString());
}
}
public static String convertDocument_String(Document Doc){
String sResult ="";
StringWriter writer = new StringWriter();
try {
DOMSource domSource = new DOMSource(Doc);
StreamResult result = new StreamResult(writer);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.transform(domSource, result);
} catch (Exception ex) {
ex.printStackTrace();
}
sResult = writer.toString();
return sResult;
}
}