如何在 C# 摘要中包含 html 标记,以便将其作为文本处理(而不是解析为 XML)?

发布于 2024-07-26 07:51:44 字数 531 浏览 2 评论 0原文

我正在用 C# 编写一个 HTML 解析器,并希望在摘要 XML 块中包含它处理的 HTML 示例。 如何防止< 和> Visual Studio 2008 自动文档混乱的字符?

示例:

  /// <summary>
  /// Creates a FlowSegment based on an HTML code, i.e. <bold>
  /// </summary>
  /// <param name="code"></param>
  /// <returns></returns>
  public FlowSegment(string code)
  {

不幸的是,该示例导致此构造函数显示工具提示(部分):

XML comment includes invalid XML

而不是摘要注释。

我怎样才能逃脱< 和> 人物?

I'm writing an HTML parser in C# and want to include examples of the HTML that it handles in the summary XML blocks. How do I prevent the < and > characters from messing up the auto-documentation of Visual Studio 2008?

example:

  /// <summary>
  /// Creates a FlowSegment based on an HTML code, i.e. <bold>
  /// </summary>
  /// <param name="code"></param>
  /// <returns></returns>
  public FlowSegment(string code)
  {

Unfortunately the example causes the tool tip for this constructor to display (in part):

XML comment includes invalid XML

instead of the summary comment.

How can I escape the < and > characters?

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

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

发布评论

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

评论(2

仅此而已 2024-08-02 07:51:44

我发现的最好的解决方案是更改它以替换 < 与 < 和 > >

使用XML 规范 中的 。

这使得示例如下所示:

  /// <summary>
  /// Creates a FlowSegment based on an HTML code, i.e. <bold>
  /// </summary>
  /// <param name="code"></param>
  /// <returns></returns>
  public FlowSegment(string code)
  {

这使得所需的工具提示正确显示。

The best solution I found was to change it so as to replace < with < and > with >

as found in the XML specifications.

That makes the example look as follows:

  /// <summary>
  /// Creates a FlowSegment based on an HTML code, i.e. <bold>
  /// </summary>
  /// <param name="code"></param>
  /// <returns></returns>
  public FlowSegment(string code)
  {

Which makes the desired tool-tip display properly.

樱&纷飞 2024-08-02 07:51:44

可能重复:
C# 摘要注释中的 Xml 字符串

另一种解决方案是使用CDATA:

  /// <summary>
  /// Creates a FlowSegment based on an HTML code, i.e. <![CDATA[ <bold> ]]>
  /// </summary>
  /// <param name="code"></param>
  /// <returns></returns>
  public FlowSegment(string code)
  {

Possible duplicate with:
Xml string in a C# summary comment

An alternative solution is also to use CDATA:

  /// <summary>
  /// Creates a FlowSegment based on an HTML code, i.e. <![CDATA[ <bold> ]]>
  /// </summary>
  /// <param name="code"></param>
  /// <returns></returns>
  public FlowSegment(string code)
  {
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文