Exemplo n.º 1
0
    public HtmlParsedTableWithHeader(HtmlNode table_node, HtmlTableParseOption?parseOption = null)
    {
        if (parseOption == null)
        {
            parseOption = new HtmlTableParseOption();
        }

        this.ParseOption = parseOption;

        this.TableNode = table_node;

        var rows = TableNode.SelectNodes("tr");

        if (rows.Count <= 0)
        {
            throw new ApplicationException("Table: rows.Count <= 0");
        }

        // ヘッダリストの取得
        HeaderList = new List <string>();

        if (ParseOption.AlternativeHeaders == null)
        {
            var header_coulmns = rows[ParseOption.SkipHeaderRowCount].SelectNodes("td");

            if (header_coulmns == null)
            {
                header_coulmns = rows[ParseOption.SkipHeaderRowCount].SelectNodes("th");
            }

            foreach (var column in header_coulmns)
            {
                HeaderList.Add(column.GetSimpleText());
            }
        }
        else
        {
            HeaderList = ParseOption.AlternativeHeaders.ToList();
        }

        // データリストの取得
        this.DataList = new List <Dictionary <string, HtmlParsedTableData> >();

        for (int i = (1 + ParseOption.SkipHeaderRowCount); i < rows.Count; i++)
        {
            var td_list = rows[i].SelectNodes("td");

            Dictionary <string, HtmlParsedTableData> data_list = new Dictionary <string, HtmlParsedTableData>();

            if (td_list.Count >= this.HeaderList.Count)
            {
                for (int j = 0; j < td_list.Count; j++)
                {
                    data_list[HeaderList[j]] = new HtmlParsedTableData(td_list[j]);
                }

                DataList.Add(data_list);
            }
        }
    }
Exemplo n.º 2
0
        public HtmlParsedTableWithHeader(HtmlNode table_node, string[] alternative_headers = null)
        {
            this.TableNode = table_node;

            var rows = TableNode.SelectNodes("tr");

            if (rows.Count <= 0)
            {
                throw new ApplicationException("Table: rows.Count <= 0");
            }

            // ヘッダリストの取得
            HeaderList = new List <string>();

            if (alternative_headers == null)
            {
                var header_coulmns = rows[0].SelectNodes("td");

                foreach (var column in header_coulmns)
                {
                    HeaderList.Add(column.GetSimpleText());
                }
            }
            else
            {
                HeaderList = alternative_headers.ToList();
            }

            // データリストの取得
            this.DataList = new List <Dictionary <string, HtmlParsedTableData> >();

            for (int i = 1; i < rows.Count; i++)
            {
                var td_list = rows[i].SelectNodes("td");


                Dictionary <string, HtmlParsedTableData> data_list = new Dictionary <string, HtmlParsedTableData>();

                if (td_list.Count != this.HeaderList.Count)
                {
                    throw new ApplicationException("td_list.Count != this.HeaderList.Count");
                }

                for (int j = 0; j < td_list.Count; j++)
                {
                    data_list[HeaderList[j]] = new HtmlParsedTableData(td_list[j]);
                }

                DataList.Add(data_list);
            }
        }
        /// <summary>
        /// 从PDM数据结构定义XML文件中加载数据结构信息
        /// </summary>
        /// <param name="doc">XML文档对象</param>
        /// <returns>加载的字段信息个数</returns>
        public int LoadFromPDMXMLDocument(XmlDocument doc)
        {
            intFillStyle = FillStyleConst.PDM;
            int RecordCount = 0;

            myTables.Clear();
            XmlNamespaceManager nsm = new XmlNamespaceManager(doc.NameTable);

            nsm.AddNamespace("a", "attribute");
            nsm.AddNamespace("c", "collection");
            nsm.AddNamespace("o", "object");
            XmlNode RootNode = doc.SelectSingleNode("/Model/o:RootObject/c:Children/o:Model", nsm);

            if (RootNode == null)
            {
                return(0);
            }
            strName        = ReadXMLValue(RootNode, "a:Name", nsm);
            strDescription = strName;
            // 数据表
            foreach (XmlNode TableNode in RootNode.SelectNodes("c:Tables/o:Table", nsm))
            {
                TableInfo table = new TableInfo();
                myTables.Add(table);
                table.Name   = ReadXMLValue(TableNode, "a:Code", nsm);
                table.Remark = ReadXMLValue(TableNode, "a:Name", nsm);
                string keyid = ReadXMLValue(TableNode, "c:PrimaryKey/o:Key/@Ref", nsm);
                System.Collections.Specialized.StringCollection Keys =
                    new System.Collections.Specialized.StringCollection();
                if (keyid != null)
                {
                    foreach (XmlNode KeyNode in TableNode.SelectNodes(
                                 "c:Keys/o:Key[@Id = '" + keyid + "']/c:Key.Columns/o:Column/@Ref", nsm))
                    {
                        Keys.Add(KeyNode.Value);
                    }
                }
                foreach (XmlNode FieldNode in TableNode.SelectNodes("c:Columns/o:Column", nsm))
                {
                    RecordCount++;
                    string    id    = ((XmlElement)FieldNode).GetAttribute("Id");
                    FieldInfo field = new FieldInfo();
                    table.Fields.Add(field);
                    field.Name        = ReadXMLValue(FieldNode, "a:Code", nsm);
                    field.Remark      = ReadXMLValue(FieldNode, "a:Name", nsm);
                    field.Description = ReadXMLValue(FieldNode, "a:Comment", nsm);
                    string FieldType = ReadXMLValue(FieldNode, "a:DataType", nsm);
                    if (FieldType != null)
                    {
                        int index = FieldType.IndexOf("(");
                        if (index > 0)
                        {
                            FieldType = FieldType.Substring(0, index);
                        }
                    }
                    field.FieldType = FieldType;

                    field.FieldWidth = ReadXMLValue(FieldNode, "a:Length", nsm);
                    if (Keys.Contains(id))
                    {
                        field.PrimaryKey = true;
                    }
                }
            }
            return(RecordCount);
        }