How does one remove all logical white spaces
See original GitHub issueHello, Is it possible to remove all logical white spaces in the final Jte output? We are using Jte for XML templating and it insists on leaving logical white spaces in our final XML documents thereby making the document invalid for some XML processors. Suppose I have the following template:
@import com.example.JteXMLIssue
@import com.example.HttpStatus
@import java.time.Instant
@import java.time.temporal.ChronoUnit
@param JteXMLIssue res
!{
var ts = Instant.now().truncatedTo(ChronoUnit.MILLIS).toString();
var message = res.message().isBlank()? HttpStatus.stringOf(200).toUpperCase(): res.message();
}
<!DOCTYPE cXML SYSTEM "http://example.com/example.dtd">
<Issue xml:lang="en-US" timestamp="${ts}" someID="${res.pid()}@internal.example.com">
<Response><Status code="${res.code()}" text="${HttpStatus.stringOf(res.code())}">${message}</Status></Response>
</Issue>
Where JteXMLIssue is defined as public record JteXMLIssue(int code, String pid, String message) {}
The template works.
However, Jte leaves leading lines in the response, and insists on reformatting the document like this:
=========blank line==========
<!DOCTYPE cXML SYSTEM "http://example.com/example.dtd">
<Issue xml:lang="en-US" timestamp="2021-05-06T08:46:07.797Z" someID="53puf4mq@internal.example.com">
<Response>
<Status code="200" text="OK">OK</Status>
</Response>
</Issue>
Reformatting is not a problem but the leading white spaces makes the document invalid for some XML readers. We tried putting the DOCTYPE line before the code block but Jte compiler complained. What can one do to remove all logical white spaces, or how do I get Jte to render something like the following with no leading white spaces or new lines:
<Issue xml:lang="en-US" timestamp="2021-05-06T08:46:07.797Z" someID="53puf4mq@internal.example.com">
<Response><Status code="200" text="OK">OK</Status></Response>
</Issue>
The following output will even be better:
<!DOCTYPE cXML SYSTEM "http://example.com/example.dtd"> <Issue xml:lang="en-US" timestamp="2021-05-06T08:46:07.797Z" someID="53puf4mq@internal.example.com"> <Response><Status code="200" text="OK">OK</Status></Response> </Issue>
Thank you for an excellent project.
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (5 by maintainers)
Top GitHub Comments
Hello @casid , Awesome! We patiently await the GA release. Furthermore, we appreciate the information and advice regarding template structural arrangement and use of layouts. I should probably note that we naturally went for layouts in some of the code base that are being migrated from JSPs. However, we trimmed down the issue report to create a minimal, complete and verifiable example for you.
We really appreciate your responsiveness and fast turn-around on this issue. Thank you.
@a1730 I just released
1.10.0
to maven central.I’m closing this issue now, feel free to reopen if there are still problems afterwards!