Technology Blog Posts by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
arrezende
Active Participant
5,354

Problem


Maybe when you execute a message mappping with the character & the error  "Unable to display tree view; Error when parsing an XML document (The entity name must immediately follow the '&' in the entity reference.)" is returned.



The solution for this problem is simple, just develop the java mapping for change the character & by &. 

 

Solution


In your Message Mapping, in the tab Functions copy and past the code below int the area Attributes and Methods, (or if you prefer, create a java mapping in NWDS with the same code, works the same way).

 
public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput) throws StreamTransformationException {
try {
InputStream inputstream = transformationInput.getInputPayload().getInputStream();
OutputStream outputstream = transformationOutput.getOutputPayload().getOutputStream();

byte[] b = new byte[inputstream.available()];
inputstream.read(b);
String encoding ="UTF-8";
String inputXML=new String(b);

inputXML = inputXML.replaceAll("&(?!amp;)", "&");
outputstream.write(inputXML.getBytes(encoding));

} catch (Exception exception) {
getTrace().addDebugMessage(exception.getMessage());
throw new StreamTransformationException(exception.toString());
}
}

 


Test


Open your Message Mapping (or operation mapping if you create a jar in NWDS), in Text View, fill the field with the & and run a test.



I hope I have collaborated with the community, and I await your feedback.

 
1 Comment