public void writeConfig(Writer configStream,boolean intend) throws Exception { MXml.trim(element); MXml.saveXml(element, configStream, intend); }
/** * Remove white spaces in the text nodes. * * @param element */ public static void trim(Element element) { if (element == null) return; NodeList nodes = element.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if (node instanceof Element) trim((Element)node); else if (node instanceof Text) { String value = ((Text)node).getNodeValue(); if (value != null) { // boolean hasEnter = value.indexOf('\n') > -1; value = value.trim(); // if (hasEnter && value.indexOf('\n') < 0) // value = value + "\n"; node.setNodeValue(value); } } } }
public void save() throws MException { try { if (!canSave()) return; log().t("save config",this); FileOutputStream os = new FileOutputStream(file); MXml.trim(element); MXml.saveXml(element, os); os.close(); } catch (Exception e) { throw new MException(e); } }