Following are the sample of my code.
OutputStream outs = response.getOutputStream();
property.put("xyz", serverpath);
property.put("*abc", serverIPAddress);
property.storeToXML(outs, null, "UTF-8");
outs.close();
I don't require DOCTYPE
declaration. How to remove it?
Current output is:
Like most of the Properties class, you can't change it. Instead, capture the XML string produced, modify it, then send it out manually.
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 you can use to capture and retrieve what was written to it. Because a Properties
object is in practice not going to have many entries, this approach does not pose a memory consumption risk.
If you already have string and want to remove it then you can make use of this
str.replaceAll("<!DOCTYPE((.|\n|\r)*?)\">", "");
Picked from here: http://www.gregbugaj.com/?p=270
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With