I would replace regexp with it. It is not very efficient, but it will certainly be faster than XML parsing!
This is not verified:
String cleaned = original.replaceAll("\\s*[\\r\\n]+\\s*", "").trim();
If I didnโt work, this will eliminate all line terminators, as well as any spaces immediately after these line terminators. The space at the beginning of the pattern should kill any trailing spaces on separate lines. trim() discarded for good measure to exclude spaces at the beginning of the first line and at the end of the last.
source share