从超过1个文件的Web API帮助页面的XML注释 [英] Web Api Help Page XML comments from more than 1 files

查看:270
本文介绍了从超过1个文件的Web API帮助页面的XML注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在用自己的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆