Compartir a través de


Can I put CDATA inside a CDATA node?

Well. The answer is no. CDATAs cannot be nested in general. The nested CDATA terminating sequence will terminate the outer CDATA. However there is a trick where you can put CDATA in two consequitive CDATA sections. It works by splitting the terminating sequence in two halves. 

There is one caviat though - VB 9.0 does not allow a sequence of more than one CDATA as a standalone object (one is fine though). You will have to put this sequence into an element  <a> ... </a>  or a fragment <> ... </> .

Here is an example (element is used):

Module Module1

    Sub Main()

        Dim c1 = _

        <a><![CDATA[<![CDATA[some cdata here]]]><![CDATA[]>]]></a>

        Dim c2 = _

        <a><![CDATA[<![CDATA[some cdata here]]]]><![CDATA[>]]></a>

        Console.WriteLine(c1.Value)

        Console.WriteLine(c2.Value)

    End Sub

End Module

========  Output:

<![CDATA[some cdata here]]>
<![CDATA[some cdata here]]>