Suggest the following program:
import java.io.StringReader;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
public class CrDemo {
public static void main(String[] args) throws Exception {
final String xml = "<a>foo \nbar \n</a>";
final TransformerFactory tf = TransformerFactory.newInstance();
final Transformer t = tf.newTransformer();
t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
t.setOutputProperty(OutputKeys.INDENT, "no");
t.setOutputProperty(OutputKeys.STANDALONE, "yes");
t.transform(new StreamSource(new StringReader(xml)), new StreamResult(System.out));
}
}
The output looks like this:
<a>foo
bar
</a>
Is it possible to prevent the Transformer from escaping CR?