0

I try to write a litte plugin for Visual studio for XML code documenation. But my code that creates the XML is not working correctly:

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();

This is the output.

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

It should be:

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

Should I use another way to create my XML?Any hints and improvments are appreciated.

3 Answers 3

4

Substitute following line

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

with

summaryElement.Add(new XText("Initializes a new instance of the "));
summaryElement.Add(refElement);
summaryElement.Add(new XText(" class."));
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, it works. Would you recommand the XElements, a XmlDocument or XmlWriter?
For your scenario, I think LINQ to XML is more appropriate choice. You may also look at this questions stackoverflow.com/questions/1542073/xdocument-or-xmldocument , stackoverflow.com/questions/1660377/xmldocument-vs-xmlwriter
0

Yes, it's escaping the < as a matter of course. There's a thread elsewhere about this, with some suggested workarounds:

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

Comments

0

The easiest way is to generate API docs from the summary XML is to use Sandcastle. See this thread for links: Are there any good automated tools to document REST APIs

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.