question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How does one remove all logical white spaces

See original GitHub issue

Hello, 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:closed
  • Created 2 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
a1730commented, May 7, 2021

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.

0reactions
casidcommented, May 8, 2021

@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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to remove all white spaces from a String in Java?
To remove all white spaces from String, use the replaceAll() method of String class with two arguments, i.e. replaceAll("\\s", ""); where \\s is ......
Read more >
Program to Remove All the White Spaces from a String
Decrease the length of the string by 1 on the termination of this loop. Repeat this process until all the white-spaces of the...
Read more >
How to remove spaces in Excel - leading, trailing, non-breaking
See how to quickly remove spaces in Excel: trim leading, trailing and extras spaces between words, get rid of non-breaking whitespace and ...
Read more >
How do i remove all white spaces from a string? - Stack Overflow
Try this : images= images.Replace(" ", String.Empty);.
Read more >
Remove All Whitespace From a String in JavaScript
Removing all whitespace can be cumbersome when it comes to tabs and line breaks. Luckily, JavaScript's string.replace() method supports regular ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found