Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do i remove the new lines introduced when converting Document to String?
    primarykey
    data
    text
    <p>I am converting an xml string to nodelist using the code,</p> <pre><code>InputSource inputSource = new InputSource(new ByteArrayInputStream( uploadFormBean.getXhtmlResponse().getBytes())); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); Document document; document = documentBuilderFactory.newDocumentBuilder().parse(inputSource); </code></pre> <p>I do the above inorder to iterate over the node list and replace of the one node elements by using the setTextContent.</p> <p>I then convert the Document to string using the below API,</p> <pre><code> ByteArrayOutputStream byteOutput = new java.io.ByteArrayOutputStream(); Result result = new StreamResult(byteOutput); Source source = new DOMSource(document); // write the DOM document to the file Transformer transformer; transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "YES"); transformer.transform(source, result); String resultText = byteOutput.toString(); System.out.println("resultText::" + resultText); </code></pre> <p>When i display the string I find that the resulting xml has got new lines introduced.</p> <p>Why is this happening? The source xml String does not have these new lines. How can this be resolved?</p> <p>When i use str.replaceAll("(\r|\n)", ""); it removes all the new lines. I do not want this to happen. I want the String back in the same way as the input. I am looking for a way to avoid the unneccesary new lines introduced in the processing.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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