ElektroStudios
ElektroStudios

Reputation: 20464

How to properly escape the content of a <code> example in Xml documentation?

Which would be the way to escape VB's and C-Sharp illegal characters like <>& in a <code> tag of .Net Xml documentation?.

In this example below, Intellisense highlights the > character because I need to escape it, it says the code will not be included when generating the documentation because that reason.

''' ------------------------------------------------------------------------
''' <summary>
''' </summary>
''' ------------------------------------------------------------------------
''' <example> This is a code example.
''' <code>
''' 
''' Dim currentPosition As Long = CLng(player.Position.TotalMilliseconds)
''' 
''' If Not ((currentPosition + 5000) >= player.Length) Then
'''    player.Seek(currentPosition + 5000)
''' End If
''' 
''' </code>
''' </example>
''' ------------------------------------------------------------------------
Sub Something
End Sub

Then, how I should escape the code content?.

I have the doubt because the content of <code> tag is treated as literal text, then if I add a CDATA tag to avoid an IntelliSense error what will happens when I'll generate the Chm/Html file with that documentation?, I mean the CDATA markup symbols will be represented as liter text in the code example causing residuous in this way, or what?.

Someone could provide an example to do things right?.

Upvotes: 5

Views: 1800

Answers (1)

Martin Soles
Martin Soles

Reputation: 559

You need to use the same type of escaping that you would in a normal XML (or HTML) document (see here for more information).

Replace & with &amp;, < with &lt;, > with &gt;. Another one you might want to watch out for is the quote character. " gets replaced with &quot;.

Upvotes: 5

Related Questions