Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get rid of line separator "
" while serializing XML file
    primarykey
    data
    text
    <p>I have a XML file in an XML editor (of an Eclipse RCP application) and I'd like to serialize properly the XML document, from the editor to an external location, into a file.</p> <p>But, while exporting the file, I have first to remove the xmlns attribute that is present into the root element.</p> <p>So that operation works fine when the document to export has a <strong>LF</strong> character as line separator but if it has a <strong>CRLF</strong> line separator, in the resulting file, I can see that the line separator has been partially encoded.</p> <p>Here is a sample of a document to export (imagine that it has <strong>CRLF</strong> as line separator) :</p> <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt; &lt;document xmlns="http://mynamespace/"&gt; &lt;entete&gt; &lt;rubrique&gt;30&lt;/rubrique&gt; &lt;meta&gt; &lt;description&gt;blablabla&lt;/description&gt; &lt;keywords&gt;bla bla bla&lt;/keywords&gt; &lt;/meta&gt; </code></pre> <p>Here is the result : </p> <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;&amp;#13; &lt;document&gt;&amp;#13; &lt;entete&gt;&amp;#13; &lt;rubrique&gt;30&lt;/rubrique&gt;&amp;#13; &lt;meta&gt;&amp;#13; &lt;description&gt;blablabla&lt;/description&gt;&amp;#13; &lt;keywords&gt;bla bla bla&lt;/keywords&gt;&amp;#13; &lt;/meta&gt;&amp;#13; </code></pre> <p>As we can see, each line has a <code>&amp;#13;</code> character...</p> <p>Here is my code</p> <pre><code>IDOMModel model = (IDOMModel) targetEditor.getAdapter(IDOMModel.class); IDOMDocument doc = model.getDocument(); FileOutputStream fos = null; String xmlns = ""; File documentFile = new File(outputDir, fileName); fos = new FileOutputStream(documentFile); doc.getDocumentElement().removeAttribute("xmlns"); DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS"); LSSerializer writer = impl.createLSSerializer(); writer.getDomConfig().setParameter("xml-declaration", Boolean.FALSE); LSOutput output = impl.createLSOutput(); output.setByteStream(fos); writer.write(model.getDocument(), output); </code></pre> <p>I tried many different options ...</p> <p>Anybody knows how to fix that ?</p> <p>Thank you in advance.</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.
    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