简体   繁体   English

如何在XML文档中表示'<'字符?

[英]How to I represent a '<' character in my XML documentation?

I've seen various questions here on SO involving Microsoft's XML documentation tags , but I'm having trouble adding some example code: 我在SO上看到了涉及Microsoft XML文档标记的各种问题,但是我无法添加一些示例代码:

/// <summary>Return the oldest acceptable timestamp for a data packet.</summary>
/// <example>
/// if( GetOldestValidResultTime() < lastResultTime )
/// {
///     Console::WriteLine("Results are too old");
/// }
/// </example>
/// <returns>The timestamp (the Milliseconds field from a raw result) of the oldest acceptable data item given the timestamp in the latest result in the internal buffer.</returns>
long GetOldestValidResultTime();

This gives me: 这给了我:

DataProcessor.h(154) : warning C4635: XML document comment applied to 'MyApp.DataProcessor.GetOldestValidResultTime': badly-formed XML: Only one top level element is allowed in an XML document.

Is there any way around this other than using &lt; 除了使用&lt;之外,还有其他方法吗&lt; which makes examples much harder to follow if you're reading the source directly as opposed to DOxygen output (for example)? 如果直接读取源代码(而不是DOxygen输出),这会使示例难以理解? ..or is the &lt; ..或是&lt; code the only option here? 在这里编码唯一的选择?

[Edit] I've tried the suggested CDATA block but it only appears to work for single-lines: [编辑]我尝试了建议的CDATA块,但它似乎仅适用于单行:

/// <example><![CDATA[ test < 5; ]]></example>
/// <example>
/// <![CDATA[ test < 5; ]]>
/// </example>

..but not multi-line comments which might actually make for a readable example: ..但不是多行注释,实际上可能会引起可读的示例:

/// <example><![CDATA[ 
/// test < 5;
/// ]]> </example>

[Edit2] Tried pierrre's suggestion of removing the \\\\'s from in front of the last two statements which predictably failed: [Edit2]尝试了Pierrre的建议,该建议从最后两个可能会失败的语句的前面删除\\\\:

/// <example><![CDATA[ 
test < 5;
]]> </example>

gives: 得到:

error C2143: syntax error : missing ';' before '<'

使用一个CDATA块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM