Skip to content

Commit

Permalink
Merging XmlUtil.java from formplayer branch.
Browse files Browse the repository at this point in the history
  • Loading branch information
OrangeAndGreen committed May 30, 2024
1 parent 5e169de commit 737f2f4
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/translate/java/org/javarosa/engine/xml/XmlUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ public static String getPrettyXml(byte[] xml) {
DOMConfiguration domConfig = lsSerializer.getDomConfig();
domConfig.setParameter("format-pretty-print", true);
domConfig.setParameter("cdata-sections", true);

// LSSerializer does not have an explicit control for ending the XML Declaration with a
// newline, hence the need for the property isStandalone
// More in https://bugs.openjdk.org/browse/JDK-8259502
domConfig.setParameter("http://www.oracle.com/xml/jaxp/properties/isStandalone", true);

lsSerializer.setNewLine(System.lineSeparator());
lsSerializer.write(document, lsOutput);
return stringWriter.toString();
Expand All @@ -52,6 +58,7 @@ public static String getPrettyXml(byte[] xml) {
private static Document parseXmlFile(String in) {
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource(new StringReader(in));
return db.parse(is);
Expand Down

0 comments on commit 737f2f4

Please sign in to comment.