Reading data from multiple XML documents for displaying WEBAPI help documents

Source: Internet
Author: User

Preface:

You have to know the Helppageconfig file, do not know that you do not need this now, so you do not have to look at the following, and so on to see no hurry. Of course, if you know this, you don't have to look at it, because you will.

method One:
new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/Documentation.xml"))
替换成
new XmlDocumentationProvider("PluginsFolder/*.xml")
改ctor函数让他支持多个XML文档
usingSystem.Xml.Linq;usingSystem.Xml.XPath; XDocument Finaldoc =NULL;foreach(stringFileinchDirectory.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 ();

Method Two: Customizing a xmldocumentationprovider that supports loading XML documents from a directory

 PublicMultixmldocumentationprovider (stringXmldocfilespath) {XDocument Finaldoc =NULL;foreach(stringFileinchDirectory.GetFiles (Xmldocfilespath, "*.xml"))        {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 Xmldocumentationprovider code looks for_documentnavigator = Finaldoc.createnavigator ();}

How to use:

config.SetDocumentationProvider(new MultiXmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/")));
 PublicXmldocumentationprovider (ienumerable<string> documentpaths) {if(Documentpaths.isnullorempty ()) {Throw NewArgumentNullException (nameof (documentpaths)); } XDocument fulldocument =NULL;foreach(Var documentpathinchDocumentpaths) {if(Documentpath = =NULL)        {Throw NewArgumentNullException (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 ();}

How to use:

New []{    HttpContext.Current.Server.MapPath ("~/bin/path.to.firstnamespace.xml"),    HttpContext.Current.Server.MapPath ("~/bin/path.to.othernamespace.xmlNew Xmldocumentationprovider (xmlpaths); config. Setdocumentationprovider (Documentationprovider);

Related articles:

Web Api Help Page XML comments from than 1 files (http://stackoverflow.com/questions/22165724/ web-api-help-page-xml-comments-from-more-than-1-files/22169357#22169357)

Address of this article:

Reading data from multiple XML documents for displaying the WEBAPI Help document (http://www.cnblogs.com/shiningrise/p/XmlDocumentationProvider.html)

Reading data from multiple XML documents for displaying WEBAPI help documents

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.