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

The following examples show how to use org.dom4j.io.OutputFormat#setExpandEmptyElements() . 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 File: XmlSchemaHelper.java    From syndesis with 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 File: XmlUtils.java    From iaf with 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();
}