Convert special characters to entities for XML output
(String value)
| 283 | * Convert special characters to entities for XML output |
| 284 | */ |
| 285 | public static String escape(String value) |
| 286 | { |
| 287 | String search = "&<>"; |
| 288 | String[] replace = {"&", "<", ">"}; |
| 289 | |
| 290 | StringBuffer buf = new StringBuffer(); |
| 291 | |
| 292 | for (int i = 0; i < value.length(); i++) |
| 293 | { |
| 294 | char c = value.charAt(i); |
| 295 | int pos = search.indexOf(c); |
| 296 | if (pos < 0) |
| 297 | buf.append(c); |
| 298 | else |
| 299 | buf.append(replace[pos]); |
| 300 | } |
| 301 | |
| 302 | return buf.toString(); |
| 303 | } |
| 304 | |
| 305 | } |
| 306 |
no test coverage detected