簡體   English   中英

通過代碼構建XML文檔

[英]Build XML documentation by code

我嘗試為Visual Studio編寫一個適用於XML代碼文檔的插件。 但是我創建XML的代碼無法正常工作:

XElement rootElement = new XElement("doc");
XElement summaryElement = new XElement("summary");

var refElement = new XElement("see");
refElement.Add(new XAttribute("cref", codeFunction.Name));
summaryElement.Value = string.Format("Initializes a new instance of the {0} class.", seeRefElement);
rootElement.Add(summaryElement);
comment = rootElement.ToString();

這是輸出。

 <doc>\\r\\n <summary>Initializes a new instance of the &lt;see cref="Form1" /&gt; class.</summary>\\r\\n</doc> 

它應該是:

 <doc>\\r\\n <summary>Initializes a new instance of the <see cref="Form1" />class.</summary>\\r\\n</doc> 

我應該使用另一種方式來創建XML嗎?任何提示和改進都是值得的。

替換下一行

summaryElement.Value = string.Format("Initializes a new instance of the {0} class.", refElement);

summaryElement.Add(new XText("Initializes a new instance of the "));
summaryElement.Add(refElement);
summaryElement.Add(new XText(" class."));

是的,它自然會轉義<。 關於此的其他地方有一個線程,其中包含一些建議的解決方法:

http://social.msdn.microsoft.com/Forums/en-US/csharplanguage/thread/413654f3-dc2d-4b96-8a7e-bde69da05866

從摘要XML生成API文檔的最簡單方法是使用Sandcastle。 請參閱此線程以獲取鏈接: 是否有任何好的自動化工具來記錄REST API

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM