I'm trying to put a java exception stack trace as a text element in an XML file. A stack trace has line breaks and a tab character in the beginning of most lines, so to display it properly, I need to show whitespace which I do by putting white-space: pre
in the XSL file. However, in the XML file I get both the white space which belongs to the stack trace and extra indentation white space. This is what ends up in the XML file:
<Comment>java.lang.Exception: foo
at ...
at ...
at ...
Caused by: java.lang.IllegalArgumentException: fee
at ...
</Comment>
All lines except the first start with 8 extra spaces when I display the XML (the last 4 spaces of the 'at' lines are the tab character). Can I change how the XML is generated or displayed to show the stack trace properly?
Code excerpts:
DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbfac.newDocumentBuilder();
Document doc = db.newDocument();
...
Element comment = doc.createElement("Comment");
comment.setTextContent(stacktrace);
XSL excerpt (the "Description" here is the same element as the "Comment" above):
<div class="GROUP">
<table class="GROUP"
style="width: 100%; table-layout: auto; white-space: pre">
<tr>
<td class="RESULT">Id</td>
<td class="RESULT">Result</td>
<td class="RESULT">Description</td>