Escape & characters and others inside XML elements

Situation:

I’m trying to escape '&' characters (and others) inside XML elements. Therefore I would like to use a Custom Plugin.

Currently only the first node will be escaped, where I expect every single node should be escaped and just the text inside the node.

The first custom plugin is correct (it unescapes all HTML in the test.xml), but the second plugin should escape the characters to HTML in case
they are between > and </ (inside the nodes).

Solution:

Custom plugin “GMN_PLUGIN_Escape_to_HTML” needs to be updated and here is the updated plugin:

 

import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import org.apache.commons.lang.StringEscapeUtils;
import com.adeptia.indigo.logging.Logger;
BufferedReader br = null;
try {
br = new BufferedReader(new InputStreamReader(inputStream));
String line;
StringBuffer sb = new StringBuffer();
while ((line = br.readLine()) != null)
{
sb.append(line);
sb.append(“\n”);
}
String unescapedString = StringEscapeUtils.unescapeHtml(sb.toString());
service.write(unescapedString.getBytes(), "default");
}
catch (Exception e)
{
if (br != null) br.close();
Logger log = service.getLogger();
log.error(e.getMessage());
throw new Exception(e.getMessage());
}

 

 

 

Have more questions? Submit a request

0 Comments

Article is closed for comments.