Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I write unescaped XML outside of a CDATA
    primarykey
    data
    text
    <p>I am trying to write XML data using Stax where the content itself is HTML</p> <p>If I try</p> <pre><code>xtw.writeStartElement("contents"); xtw.writeCharacters("&lt;b&gt;here&lt;/b&gt;"); xtw.writeEndElement(); </code></pre> <p>I get this</p> <pre><code>&lt;contents&gt;&amp;lt;b&amp;gt;here&amp;lt;/b&amp;gt;&lt;/contents&gt; </code></pre> <p>Then I notice the CDATA method and change my code to:</p> <pre><code>xtw.writeStartElement("contents"); xtw.writeCData("&lt;b&gt;here&lt;/b&gt;"); xtw.writeEndElement(); </code></pre> <p>and this time the result is</p> <pre><code>&lt;contents&gt;&lt;![CDATA[&lt;b&gt;here&lt;/b&gt;]]&gt;&lt;/contents&gt; </code></pre> <p>which is still not good. <strong>What I really want is</strong> </p> <pre><code>&lt;contents&gt;&lt;b&gt;here&lt;/b&gt;&lt;/contents&gt; </code></pre> <p>So is there an XML API/Library that allows me to write raw text without being in a CDATA section? So far I have looked at Stax and JDom and they do not seem to offer this.</p> <p>In the end I might resort to good old StringBuilder but this would not be elegant.</p> <p><strong>Update:</strong></p> <p>I agree mostly with the answers so far. However instead of <code>&lt;b&gt;here&lt;/b&gt;</code> I could have a 1MB HTML document that I want to embed in a bigger XML document. What you suggest means that I have to parse this HTML document in order to understand its structure. I would like to avoid this if possible. </p> <p><strong>Answer:</strong></p> <p>It is not possible, otherwise you could create invalid XML documents.</p>
    singulars
    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.
 

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