你的位置:首页 > ASP.net教程

[ASP.net教程]从多个XML文档中读取数据用于显示webapi帮助文档


前言:

你先得知道HelpPageConfig文件,不知道说明你现在不需要这个,所以下文就不用看了,等知道了再看也不急.当然如果你很知道这个,下文也不用看了,因为你会了.

方法一:

new 
替换成
new 
改ctor函数让他支持多个
using System.using System.null; foreach (string file in Directory.GetFiles(@"PluginsFolder", "*.")) {  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 _documentNavigator = finalDoc.CreateNavigator();

方法二: 自定义一个支持从目录加载

public Multistring null;    foreach (string file in Directory.GetFiles(*."))    {      using (var fileStream = File.OpenRead(file))      {        if (finalDoc == null)        {          finalDoc = XDocument.Load(fileStream);        }        else        {          XDocument xdocAdditional = XDocument.Load(fileStream);          finalDoc.Root.XPathSelectElement("/doc/members")            .Add(xdocAdditional.Root.XPathSelectElement("/doc/members").Elements());        }      }    }    // Supply the navigator that rest of the     _documentNavigator = finalDoc.CreateNavigator();}

使用方法:

config.SetDocumentationProvider(new Multi
方法三:给默认的
public string> documentPaths){  if (documentPaths.IsNullOrEmpty())  {    throw new ArgumentNullException(nameof(documentPaths));  }  XDocument fullDocument = null;  foreach (var documentPath in documentPaths)  {    if (documentPath == null)    {      throw new ArgumentNullException(nameof(documentPath));    }    if (fullDocument == null)    {      using (var stream = File.OpenRead(documentPath))      {        fullDocument = XDocument.Load(stream);      }    }    else    {      using (var stream = File.OpenRead(documentPath))      {        var additionalDocument = XDocument.Load(stream);        fullDocument?.Root?.XPathSelectElement("/doc/members").Add(additionalDocument?.Root?.XPathSelectElement("/doc/members").Elements());      }    }  }  _documentNavigator = fullDocument?.CreateNavigator();}

使用方法:

var new[]{  HttpContext.Current.Server.MapPath("~/bin/Path.To.FirstNamespace."),  HttpContext.Current.Server.MapPath("~/bin/Path.To.OtherNamespace.")};var documentationProvider = new 

相关文章:

Web Api Help Page

本文地址:

从多个