Ejrr1085
Ejrr1085

Reputation: 1071

How to set XML code in NET XML documentation comments

I want to add XML code in -NET C# XML documentation, i found this help: https://stackoverflow.com/a/11030588/2825284 but not work

        /// <summary>
        /// My comentary:
        /// <code>
        ///     <MyXmlCode>
        ///         <XmlNode Atribute="34"/>
        ///     </MyXmlCode>
        /// </code>
        /// </summary>

Upvotes: 1

Views: 84

Answers (1)

Peter Macej
Peter Macej

Reputation: 5607

Your example code contains reserved XML characters that need to be escaped. These characters and their escape sequences are:

< ... &lt;
> ... &gt;
& ... &amp;

So your comment needs to be:

        /// <summary>
        /// My comentary:
        /// <code>
        ///     &lt;MyXmlCode&gt;
        ///         &lt;XmlNode Atribute="34"/&gt;
        ///     &lt;/MyXmlCode&gt;
        /// </code>
        /// </summary>

Or, to make it more readable, use CDATA:

        /// <summary>
        /// My comentary:
        /// <code><![CDATA[
        ///     <MyXmlCode>
        ///         <XmlNode Atribute="34"/>
        ///     </MyXmlCode>
        /// ]]></code>
        /// </summary>

BTW, our VSdocman contains the comment editor which produces CDATA. One drawback of CDATA is that Intellisense doesn't show it currently.

Upvotes: 1

Related Questions