Java Code Examples for org.dom4j.io.OutputFormat#setExpandEmptyElements()

The following examples show how to use org.dom4j.io.OutputFormat#setExpandEmptyElements() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: syndesis   File: XmlSchemaHelper.java    License: Apache License 2.0 5 votes vote down vote up
public static String serialize(final Document document) {
    try (StringWriter out = new StringWriter()) {
        final OutputFormat format = new OutputFormat(null, false, "UTF-8");
        format.setExpandEmptyElements(false);
        format.setIndent(false);

        final XMLWriter writer = new XMLWriter(out, format);
        writer.write(document);
        writer.flush();

        return out.toString();
    } catch (final IOException e) {
        throw new IllegalStateException("Unable to serialize given document to XML", e);
    }
}
 
Example 2
Source Project: iaf   File: XmlUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static String canonicalize(String input) throws DocumentException, IOException {
	if (StringUtils.isEmpty(input)) {
		return null;
	}
	org.dom4j.Document doc = DocumentHelper.parseText(input);
	StringWriter sw = new StringWriter();
	OutputFormat format = OutputFormat.createPrettyPrint();
	format.setExpandEmptyElements(true);
	XMLWriter xw = new XMLWriter(sw, format);
	xw.write(doc);
	return sw.toString();
}