Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>S. Lott's answer is right: you don't encode the end tag, you break it across multiple CDATA sections.</p> <p>How to run across this problem in the real world: using an XML editor to create an XML document that will be fed into a content-management system, try to write an article about CDATA sections. Your ordinary trick of embedding code samples in a CDATA section will fail you here. You can imagine how I learned this.</p> <p>But under most circumstances, you won't encounter this, and here's why: if you want to store (say) the text of an XML document as the content of an XML element, you'll probably use a DOM method, e.g.:</p> <pre><code>XmlElement elm = doc.CreateElement("foo"); elm.InnerText = "&lt;[CDATA[[Is this a problem?]]&gt;"; </code></pre> <p>And the DOM quite reasonably escapes the &lt; and the >, which means that you haven't inadvertently embedded a CDATA section in your document.</p> <p>Oh, and this is interesting:</p> <pre><code>XmlDocument doc = new XmlDocument(); XmlElement elm = doc.CreateElement("doc"); doc.AppendChild(elm); string data = "&lt;![[CDATA[This is an embedded CDATA section]]&gt;"; XmlCDataSection cdata = doc.CreateCDataSection(data); elm.AppendChild(cdata); </code></pre> <p>This is probably an ideosyncrasy of the .NET DOM, but that doesn't throw an exception. The exception gets thrown here:</p> <pre><code>Console.Write(doc.OuterXml); </code></pre> <p>I'd guess that what's happening under the hood is that the XmlDocument is using an XmlWriter produce its output, and the XmlWriter checks for well-formedness as it writes.</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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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