/// <summary> /// 获取用于分析 HTML 文档的分析器 /// </summary> /// <param name="contentResult">文档内容加载结果</param> /// <returns>HTML 分析器相关信息</returns> public static IHtmlParser GetParser(HtmlContentResult contentResult) { if (contentResult == null) { throw new ArgumentNullException("contentResult"); } lock ( _parserProvidersSync ) { foreach (var provider in ParserProviders) { var parser = provider.GetParser(contentResult.VirtualPath, contentResult.Content); if (parser != null) { return(parser); } } } //默认行为 return(DefaultParserProvider.GetParser(contentResult.VirtualPath, contentResult.Content)); }
/// <summary> /// 获取用于分析 HTML 文档的分析器 /// </summary> /// <param name="context">当前请求上下文</param> /// <param name="contentUri">内容的地址</param> /// <param name="htmlContent">HTML 文档内容</param> /// <returns>HTML 分析器相关信息</returns> public static HtmlParserResult GetParser(HttpContextBase context, Uri contentUri, string htmlContent) { if (context == null) { throw new ArgumentNullException("context"); } if (contentUri != null && !contentUri.IsAbsoluteUri) { throw new ArgumentException("contentUri只能为null或绝对URI", "contentUri"); } lock ( _parserProvidersSync ) { foreach (var provider in ParserProviders) { var result = provider.GetParser(context, contentUri, htmlContent); if (result != null) { result.Provider = provider; return(result); } } } //默认行为 return(DefaultParserProvider.GetParser(context, contentUri, htmlContent)); }