/// <summary> /// 显示Html解析config的全部信息 /// </summary> /// <param name="path">config路径</param> /// <param name="targetNodes">返回全部信息</param> /// <returns></returns> public int ShowHtmlNode(string path, out List <RulesStruct> targetNodes) { targetNodes = new List <RulesStruct>(); List <HtmlExtract.RulesStruct> lhe = new List <HtmlExtract.RulesStruct>(); he.ShowWebXml(path, out lhe); foreach (var item in lhe) { RulesStruct rs = new RulesStruct(); rs.Link = item.Link; rs.Rules = item.Rules; targetNodes.Add(rs); } return(1); }
public int ShowWebXml(string path, out List <RulesStruct> targetNodes) { try { InitialConfig(path); //定义并从xml文件中加载节点(根节点) // path = @"D:\Backup\HtmlRulesBackup.config"; XElement rootNode = XElement.Load(path); //查询语句: 获得根节点下Net子节点 IEnumerable <XElement> Nodes = from target in rootNode.Descendants("Website") select target; targetNodes = new List <RulesStruct>(); foreach (var item in Nodes) { //取值并重置 RulesStruct ns = new RulesStruct(); string Link = item.Element("Link").ToString(); Link = Link.Replace("</Link>", ""); Link = Link.Replace("<Link>", ""); ns.Link = Link; string Rules = item.Element("Rules").ToString(); Rules = Rules.Replace("</Rules>", ""); Rules = Rules.Replace("<Rules>", ""); ns.Rules = Rules; targetNodes.Add(ns); } } catch (Exception e) { Console.WriteLine(e); throw; } return(1); }