Remove <! DOCTYPE from property.storeToXML property output
3 answers
Like most property classes, you cannot change it. Instead, take the resulting XML string, modify it, and then manually submit it.
property.put("xyz", "serverpath");
property.put("*abc", "serverIPAddress");
ByteArrayOutputStream out = new ByteArrayOutputStream();
property.storeToXML(out, null, "UTF-8");
String str = out.toString("UTF-8").replaceAll("<!DOCTYPE[^>]*>\n", "");
byte[] bytes = str.getBytes("UTF-8");
OutputStream outs = response.getOutputStream();
outs.write(bytes, 0, bytes.length);
outs.close();
FYI ByteArrayOutputStream
is an in-memory output stream that you can use to capture and retrieve what was written in it. Since Properties
there won't be many records in the object in practice, this approach does not pose a risk of memory consumption.
+2
source to share
If you already have a line and want to delete it, you can use this
str.replaceAll("<!DOCTYPE((.|\n|\r)*?)\">", "");
Selected from here: http://www.gregbugaj.com/?p=270
0
source to share