Skip to content

Commit

Permalink
remove superfluous newlines in XML while keeping ones separating blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
rbouckaert committed Mar 22, 2022
1 parent e8a08c4 commit 37f47d8
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/beast/util/XMLProducer.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,25 @@ public String toXML(Object beastObject, Collection<BEASTInterface> others) {
xml = dedupName(xml);
xml = sortTags(xml);

// remove double newlines introduced by XSL transformation
StringBuilder b = new StringBuilder();
for (int i = 0; i < xml.length(); i++) {
char c = xml.charAt(i);
if (c == '\n') {
int j = 0;
while (i < xml.length()-1 && xml.charAt(i+1) == ' ') {
i++;
j++;
}
if (i < xml.length()-1 && xml.charAt(i+1) == '\n') {
i++;
} else {
i = i - j;
}
}
b.append(c);
}
xml = b.toString();

//insert newlines in alignments
int k = xml.indexOf("<data ");
Expand Down

0 comments on commit 37f47d8

Please sign in to comment.