Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>After a lot of work I found two solutions to my own problem, they are more workarounds than real solutions:</p> <p><strong>Solution 1</strong></p> <p>Create a class that extends FilterOutputStream and implement the necessary methods to write every character on the final stream (a File in the case above) except for those unneeded, i.e. <code>&amp;#13;</code> To write to stream just add the filter:</p> <pre><code> StreamResult result = new StreamResult( new OutputStreamWriter( new XMLFilterOutputStream( new FileOutputStream(filename)),"UTF-8")); transformer.transform(source, result); </code></pre> <p><strong>Solution 2</strong></p> <p>When creating the DOM tree just escape the \r character (thus removing every Carriage Return from the original text):</p> <pre><code>String util = //original string data Element desc = doc.createElement("desc"); Node text = doc.createTextNode((util!=null ? stringEscape(util).trim() : "")); desc.appendChild(text); externalElement.appendChild(desc); </code></pre> <p>And having the escaping method done this way:</p> <pre><code>private String stringEscape(String str){ StringBuffer st = new StringBuffer(str); for(int i=0; i &lt; st.length();i++){ String s = st.substring(i,i+1); if("\r".equals(s)){ st.replace(i,i+1,""); } } return st.toString(); } </code></pre> <p>I know, it's <em>horrible</em>, but works.</p> <p>The correct solution, AFAIK, should be accessing the HTMLEntities file in XALAN and modify that one, therefore forcing the transformer to omit some entities.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload