Skip to content

Commit

Permalink
Merge pull request #1410 from dimagi/dv/line_separator
Browse files Browse the repository at this point in the history
Use System.lineSeparator in XmlUtil (for Windows compatibility)
  • Loading branch information
OrangeAndGreen authored May 31, 2024
2 parents 96803bf + 03b0fff commit e5cb43f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/test/resources/pretty_printed_xml.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?><h:html xmlns:h="http://www.w3.org/1999/xhtml" xmlns:jr="http://openrosa.org/javarosa" xmlns:orx="http://openrosa.org/jr/xforms" xmlns:vellum="http://commcarehq.org/xforms/vellum" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<?xml version="1.0" encoding="UTF-8"?>
<h:html xmlns:h="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/2002/xforms" xmlns:jr="http://openrosa.org/javarosa" xmlns:orx="http://openrosa.org/jr/xforms" xmlns:vellum="http://commcarehq.org/xforms/vellum" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<h:head>
<h:title>Basic Form</h:title>
<model>
<model xmlns="http://www.w3.org/2002/xforms">
<instance>
<data name="Basic Form" uiVersion="1" version="1" xmlns:jrm="http://dev.commcarehq.org/jr/xforms">
<data xmlns="http://openrosa.org/formdesigner/02FD4762-52FB-404C-9AF1-5F67894D1521" name="Basic Form" uiVersion="1" version="1" xmlns:jrm="http://dev.commcarehq.org/jr/xforms">
<q_name/>
<orx:meta xmlns:cc="http://commcarehq.org/xforms">
<orx:deviceID/>
Expand Down Expand Up @@ -53,7 +54,7 @@
</model>
</h:head>
<h:body>
<input ref="/data/q_name">
<input xmlns="http://www.w3.org/2002/xforms" ref="/data/q_name">
<label ref="jr:itext('q_name-label')"/>
</input>
</h:body>
Expand Down
9 changes: 8 additions & 1 deletion src/translate/java/org/javarosa/engine/xml/XmlUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ public static String getPrettyXml(byte[] xml) {
DOMConfiguration domConfig = lsSerializer.getDomConfig();
domConfig.setParameter("format-pretty-print", true);
domConfig.setParameter("cdata-sections", true);
lsSerializer.setNewLine("\n");

// 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();
} catch (Exception e) {
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 e5cb43f

Please sign in to comment.