diff --git a/api/src/main/java/org/openmrs/module/htmlformentry/HtmlFormEntryGenerator.java b/api/src/main/java/org/openmrs/module/htmlformentry/HtmlFormEntryGenerator.java index bfeb2b05d..f11fd1a72 100644 --- a/api/src/main/java/org/openmrs/module/htmlformentry/HtmlFormEntryGenerator.java +++ b/api/src/main/java/org/openmrs/module/htmlformentry/HtmlFormEntryGenerator.java @@ -133,7 +133,7 @@ public String applyMacros(FormEntrySession session, String xml) throws Exception content.removeChild(macrosNode); // switch back to String mode from the document so we can use string utilities to substitute - xml = HtmlFormEntryUtil.documentToString(doc); + xml = HtmlFormEntryUtil.documentToString(doc, false); // substitute any macros we found for (Object temp : macros.keySet()) { @@ -240,7 +240,7 @@ public String processPages(FormEntrySession session, String xml) throws Exceptio doc.renameNode(pageNodes.item(y), null, "div"); } - xml = HtmlFormEntryUtil.documentToString(doc); + xml = HtmlFormEntryUtil.documentToString(doc, false); return xml; } @@ -303,7 +303,7 @@ public String applyTranslations(String xml, FormEntryContext context) throws Exc content.removeChild(transNode); // switch back to String mode from the document so we can use string utilities to substitute - xml = HtmlFormEntryUtil.documentToString(doc); + xml = HtmlFormEntryUtil.documentToString(doc, false); return xml; } @@ -518,7 +518,7 @@ else if (formPath.toLowerCase().endsWith(".css")) { nodesToReplace = doc.getElementsByTagName(SUBFORM); } } - xml = HtmlFormEntryUtil.documentToString(doc); + xml = HtmlFormEntryUtil.documentToString(doc, false); } return xml; } diff --git a/api/src/main/java/org/openmrs/module/htmlformentry/HtmlFormEntryUtil.java b/api/src/main/java/org/openmrs/module/htmlformentry/HtmlFormEntryUtil.java index 043a29b18..88784904c 100644 --- a/api/src/main/java/org/openmrs/module/htmlformentry/HtmlFormEntryUtil.java +++ b/api/src/main/java/org/openmrs/module/htmlformentry/HtmlFormEntryUtil.java @@ -357,17 +357,33 @@ public static Document stringToDocument(String xml) throws Exception { } /** - * Converts a Document object to an xml string + * Converts a Document object to an xml string, indenting the output * * @param document the Document instance to convert * @return the resulting xml string * @throws Exception */ public static String documentToString(Document document) throws Exception { + return documentToString(document, true); + } + + /** + * Converts a Document object to an xml string + * + * @param document the Document instance to convert + * @param indent whether to indent the resulting xml. This should only be set to true if the + * resulting xml is intended for human consumption (e.g. exporting a form for + * editing). Indenting inserts whitespace text nodes around element boundaries, + * which corrupts mixed text/element content, most notably a {@code } or + * other substitution tag nested within a {@code