コード例 #1
0
        /// <summary>
        /// 获取表尾巴中的所有的input标签的数据,注意没有select
        /// </summary>
        /// <param name="doc"></param>
        /// <returns></returns>
        public static Dictionary <int, List <MYDataHead> > GetFootData(HtmlAgilityPack.HtmlDocument doc)
        {
            var data = new Dictionary <int, List <MYDataHead> >();

            //表头
            Dictionary <int, HtmlAgilityPack.HtmlNodeCollection> tfootOfInputAndSelect = AnalyticHTML.GetTfootOfInputAndSelect(doc);

            //遍历通道
            foreach (var item in tfootOfInputAndSelect.Keys)
            {
                HtmlAgilityPack.HtmlNodeCollection body = tfootOfInputAndSelect[item];
                List <MYDataHead> list = new List <MYDataHead>();
                foreach (var b in body)
                {
                    MYDataHead mydata = new MYDataHead();
                    mydata.id   = b.Attributes["id"].Value;
                    mydata.name = b.Attributes["name"].Value;

                    if (b.Name == "input")
                    {
                        if (b.Attributes["value"] != null)
                        {
                            mydata.value = b.Attributes["value"].Value;
                        }
                    }
                    else if (b.Name == "select")
                    {
                        var nodes = b.ChildNodes
                                    .Where(w => (w.Name == "option" && w.Attributes["selected"] != null))
                                    .Select(s => s.Attributes["value"].Value).FirstOrDefault();

                        if (null == (nodes))
                        {
                            mydata.value = b.ChildNodes
                                           .Where(w => (w.Name == "option"))
                                           .Select(s => s.Attributes["value"].Value).First();
                        }
                        else
                        {
                            mydata.value = nodes;
                        }
                    }

                    list.Add(mydata);
                }
                data.Add(item, list);
            }
            return(data);
        }
コード例 #2
0
ファイル: CreatXML.cs プロジェクト: zhxy323/SHIYANSHI
        public static string Create(HtmlAgilityPack.HtmlDocument doc, string RuleID)
        {
            try
            {
                //表头
                Dictionary <int, HtmlAgilityPack.HtmlNodeCollection> theadOfInputAndSelect = AnalyticHTML.GetTheadOfInputAndSelect(doc);
                //表身
                Dictionary <int, HtmlAgilityPack.HtmlNodeCollection> tbodyOfInputAndSelect = AnalyticHTML.GetTBodyOfInputAndSelect(doc);
                //表尾巴
                Dictionary <int, HtmlAgilityPack.HtmlNodeCollection> tfootOfInputAndSelect = AnalyticHTML.GetTfootOfInputAndSelect(doc);
                //表头的xml字符串
                string outHead = "";

                //只遍历通道1
                if (theadOfInputAndSelect != null && theadOfInputAndSelect.Count > 0)
                {
                    var tongdao1 = theadOfInputAndSelect[1];
                    for (int i = 0; i < tongdao1.Count; i++)
                    {
                        outHead += string.Format(tempCell, tongdao1[i].Attributes["name"].Value, i);
                    }
                }
                outHead = string.Format(tempCellList, outHead);

                outHead = string.Format(tempRowNumber, outHead, AnalyticHTML.GetTheadOfTR(doc));

                //表体的xml字符串
                string outBody = "";
                if (tbodyOfInputAndSelect != null && tbodyOfInputAndSelect.Count > 0)
                {
                    //只遍历通道1
                    var tongdao1OfBodyOfInputAndSelect = tbodyOfInputAndSelect[1];
                    //将name去重
                    var tongdao1OfBodyOfInputAndSelectAttributes = (from b in tongdao1OfBodyOfInputAndSelect
                                                                    // where b.Attributes["name"] != null//hidden标签会为空
                                                                    select b.Attributes["name"].Value).Distinct().ToList();

                    for (int i = 0; i < tongdao1OfBodyOfInputAndSelectAttributes.Count; i++)
                    {
                        outBody += string.Format(tempCell, tongdao1OfBodyOfInputAndSelectAttributes[i], i);
                    }
                    outBody = string.Format(tempCellList, outBody);
                }

                //表体的xml字符串
                string outFoot = "";

                //只遍历通道1
                if (tfootOfInputAndSelect != null && tfootOfInputAndSelect.Count > 0)
                {
                    var tongdao1OfFootOfInputAndSelect = tfootOfInputAndSelect[1];
                    //将name去重
                    var tongdao1OfFootOfInputAndSelectAttributes = (from b in tongdao1OfFootOfInputAndSelect
                                                                    // where b.Attributes["name"] != null//hidden标签会为空
                                                                    select b.Attributes["name"].Value).Distinct().ToList();

                    for (int i = 0; i < tongdao1OfFootOfInputAndSelectAttributes.Count; i++)
                    {
                        outFoot += string.Format(tempCell, tongdao1OfFootOfInputAndSelectAttributes[i], i);
                    }
                    outFoot = string.Format(tempCellList, outFoot);
                }

                //表格xml
                string outXML = "";
                return(outXML = string.Format(temp,
                                              RuleID,
                                              "-1" /*数据模板开始行号*/,
                                              "-1" /*备注模板行号*/,
                                              "-1" /*结论模板行号*/,
                                              "-1" /*表格表头行号*/,
                                              outHead,
                                              outFoot,/*尾巴行号*/
                                              outBody
                                              ));
            }
            catch (System.Exception ex)
            {
                throw;
            }
        }