format.setLineSeparator(LINE_SEP); } else { format.setLineSeparator("");
/** * Set the format line separator character. * @param sep line separator character */ public void setLineSeparator(String sep) { format.setLineSeparator(sep); }
/** * DOM L3 EXPERIMENTAL: * The end-of-line sequence of characters to be used in the XML being * written out. The only permitted values are these: * <dl> * <dt><code>null</code></dt> * <dd> * Use a default end-of-line sequence. DOM implementations should choose * the default to match the usual convention for text files in the * environment being used. Implementations must choose a default * sequence that matches one of those allowed by 2.11 "End-of-Line * Handling". </dd> * <dt>CR</dt> * <dd>The carriage-return character (#xD).</dd> * <dt>CR-LF</dt> * <dd> The * carriage-return and line-feed characters (#xD #xA). </dd> * <dt>LF</dt> * <dd> The line-feed * character (#xA). </dd> * </dl> * <br>The default value for this attribute is <code>null</code>. */ public void setNewLine(String newLine) { serializer._format.setLineSeparator(newLine); }
private void copySettings(XMLSerializer src, XMLSerializer dest) { dest.fDOMErrorHandler = fErrorHandler; dest._format.setEncoding(src._format.getEncoding()); dest._format.setLineSeparator(src._format.getLineSeparator()); dest.fDOMFilter = src.fDOMFilter; }//copysettings
public String format(String unformattedXml) { if (!xmlFormatterConfig.isEnableXmlFormatter()) { return unformattedXml; } try { final Document document = parseXmlFile(unformattedXml); OutputFormat format = new OutputFormat(document); format.setLineWidth(xmlFormatterConfig.getMaximumLineWidth()); format.setIndenting(true); format.setIndent(xmlFormatterConfig.getIndent()); format.setLineSeparator(System.getProperty("line.separator")); Writer out = new StringWriter(); XMLSerializer serializer = new XMLSerializer(out, format); serializer.serialize(document); return out.toString(); } catch (Exception e) { log.warn("Could not format the content: " + unformattedXml); throw new RuntimeException(e); } }
public String format(String unformattedXml) { if (!xmlFormatterConfig.isEnableXmlFormatter()) { return unformattedXml; } try { final Document document = parseXmlFile(unformattedXml); OutputFormat format = new OutputFormat(document); format.setLineWidth(xmlFormatterConfig.getMaximumLineWidth()); format.setIndenting(true); format.setIndent(xmlFormatterConfig.getIndent()); format.setLineSeparator(System.getProperty("line.separator")); Writer out = new StringWriter(); XMLSerializer serializer = new XMLSerializer(out, format); serializer.serialize(document); return out.toString(); } catch (Exception e) { log.warn("Could not format the content: " + unformattedXml); throw new RuntimeException(e); } }