Skip to Content
Technical Articles
Author's profile photo Alexandre Rezende

Solve problem with “&” in Message Mapping (Without java mapping in NWDS)

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.

 

Assigned Tags

      1 Comment
      You must be Logged on to comment or reply to a post.
      Author's profile photo Yves Bernier
      Yves Bernier

      In your test, your source and target have the same format, all good but if you are using a mapping then the mapping wont be executed and the source format will be copied to the target format without any mapping.