我如何代表一个'<'我的 XML 文档中的字符?

发布于 2024-09-07 14:51:23 字数 1675 浏览 1 评论 0 原文

我在这里看到了关于 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();

这给了我:

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.

除了使用 &lt; 之外,还有什么办法可以解决这个问题吗?如果您正在阅读源代码,这会使示例更难以理解直接与 DOxygen 输出相反(例如)? ..或者 &lt; 代码是这里唯一的选择吗?

[编辑] 我已经尝试了建议的 CDATA 块,但它似乎只适用于单行:

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

..但不适用于实际上可能构成可读示例的多行注释:

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

[ Edit2] 尝试了 pierrre 的建议,即从最后两个语句前面删除 \\,这可预见地失败了:

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

给出:

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

I've seen various questions here on SO involving Microsoft's XML documentation tags, but I'm having trouble adding some example code:

/// <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 < which makes examples much harder to follow if you're reading the source directly as opposed to DOxygen output (for example)? ..or is the < code the only option here?

[Edit] I've tried the suggested CDATA block but it only appears to work for single-lines:

/// <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:

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

gives:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

帝王念 2024-09-14 14:51:23

使用 CDATA 块。

Use a CDATA block.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文