Escaping "<"

Jelks Cabaniss jelks at jelks.nu
Sun Apr 24 00:40:51 EDT 2005


A. Pagaltzis wrote:

>> Same goes for `>`.
> 
> This, however, is not, because:
> 
>     <p>&gt;[[ Nope, not well-formed. ]]></p>
> 
> The literal sequence `]]>` cannot be part of a well-formed
> document. It is only legal as the closing delimited of a
> `<![CDATA[ ]]>` section or similar constructs.
> 
> You are almost never going to encounter this edge case, of
> course, but this is the reason why most all XML serializers
> emit &gt; for a literal closing angle bracket. 

You are absolutely right -- I had forgotten about the "except when preceded by `]]`" bit.  

You can even see it clearly in action using IE or Firefox to view a short XML snippet.  This (foo.xml) parses just fine:

    <doc>
    This is an XML document with a > in it.
    </doc>

While this (bar.xml) gives you a big "whoops":

    <doc>
    This is an XML document with a ]]> in it.
    </doc>

A non-CDATA-ending `]]>` is indeed an edge case, but mea culpa nonetheless.  


/Jelks



More information about the Markdown-Discuss mailing list