从超过1个文件的Web API帮助页面的XML注释 [英] Web Api Help Page XML comments from more than 1 files
问题描述
我在用自己的XML文档我的Web API项目不同的插件,并有一个集中的帮助页面,但问题是,网页API的默认帮助页面仅支持单文档文件
新XmlDocumentationProvider(HttpContext.Current.Server.MapPath(〜/ App_Data文件/ Documentation.xml))
这怎么可能加载从不同的文件配置?我婉做某事是这样的:
新XmlDocumentationProvider(PluginsFolder / *。xml的)
您可以在区修改安装
做类似如下: XmlDocumentationProvider
\\ HelpPage
合并多个xml文件的文件到一个单一的一种:
例子code(缺少一些错误检查和验证):
使用System.Xml.Linq的;
使用System.Xml.XPath; 的XDocument finalDoc = NULL;
的foreach(在Directory.GetFiles串文件(@PluginsFolder,*的.xml))
{
如果(finalDoc == NULL)
{
finalDoc = XDocument.Load(File.OpenRead(文件));
}
其他
{
的XDocument xdocAdditional = XDocument.Load(File.OpenRead(文件)); finalDoc.Root.XPathSelectElement(/ DOC /成员)
。新增(xdocAdditional.Root.XPathSelectElement(/ DOC /成员)元素());
}
}//供应的休息XmlDocumentationProvider code的导航仪查找
_documentNavigator = finalDoc.CreateNavigator();
I have different plugins in my Web api project with their own XML docs, and have one centralized Help page, but the problem is that Web Api's default Help Page only supports single documentation file
new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/Documentation.xml"))
How is it possible to load config from different files? I wan to do sth like this:
new XmlDocumentationProvider("PluginsFolder/*.xml")
You can modify the installed XmlDocumentationProvider
at Areas\HelpPage
to do something like following:
Merge multiple Xml document files into a single one:
Example code(is missing some error checks and validation):
using System.Xml.Linq;
using System.Xml.XPath;
XDocument finalDoc = null;
foreach (string file in Directory.GetFiles(@"PluginsFolder", "*.xml"))
{
if(finalDoc == null)
{
finalDoc = XDocument.Load(File.OpenRead(file));
}
else
{
XDocument xdocAdditional = XDocument.Load(File.OpenRead(file));
finalDoc.Root.XPathSelectElement("/doc/members")
.Add(xdocAdditional.Root.XPathSelectElement("/doc/members").Elements());
}
}
// Supply the navigator that rest of the XmlDocumentationProvider code looks for
_documentNavigator = finalDoc.CreateNavigator();
这篇关于从超过1个文件的Web API帮助页面的XML注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!