FeedElement
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using ZmjTool;
namespace ZmjConvert
{
public class FeedElement : CHtmlElement<FeedElement>
{
public static bool TryParse(string htmlstr, out IEnumerable<FeedElement> eles, out string message)
{
try
{
htmlstr = Regex.Replace(htmlstr, @"[\f\n\r\t\v]", string.Empty);
eles = Parse(htmlstr);
message = string.Empty;
return true;
}
catch (Exception e)
{
eles = null;
message = "feed文档解析异常:" + e.Message;
return false;
}
}
/// <summary>
/// 获取所有的link的href的内容,及可能存在的作者的链接
/// </summary>
/// <param name="baseUrl"></param>
/// <returns></returns>
public static List<string> GetAllLink(List<string> array, Uri srcurl, IEnumerable<FeedElement> ele)
{
array = array ?? new List<string>();
foreach (FeedElement item in ele)
{
if (item.TagName.Equals("link") && item.Attributes.TryGetValue("href", out var href) && new Uri(srcurl, href.Contains("<") ? System.Security.SecurityElement.FromString(href).Text : href) is Uri uri) array.Add(uri.AbsoluteUri);
array = GetAllLink(array, srcurl, item.Children.ToArray());
}
return array;
}
}
}