コード例 #1
0
        public void xmlparser(String path)
        {
            XmlDocument spldoc = new XmlDocument();

            spldoc.PreserveWhitespace = false;
            spldoc.Load(path);

            XmlNode     root        = spldoc.DocumentElement;
            XmlNodeList allcategory = root.SelectNodes("CATEGORY");

            List <RuleItem> TreeViewList = new List <RuleItem>();

            foreach (XmlNode category in allcategory)
            {
                //Console.WriteLine(category.Attributes["name"].Value);
                RuleItem RuleRoot = new RuleItem(category.Attributes["name"].Value);

                foreach (XmlNode subcategory in category.ChildNodes)
                {
                    //Console.WriteLine(subcategory.Attributes["name"].Value);
                    RuleItem asubcategory = new RuleItem(subcategory.Attributes["name"].Value);
                    foreach (XmlNode item in subcategory.ChildNodes)
                    {
                        RuleItem arule = new RuleItem(item.Attributes["name"].Value);
                        arule.Text = item.Attributes["text"].Value;
                        asubcategory.Children.Add(arule);
                        //Console.WriteLine(item.Attributes["name"].Value);
                    }
                    RuleRoot.Children.Add(asubcategory);
                }

                RuleRoot.Initialize();
                TreeViewList.Add(RuleRoot);
            }

            selectList.ItemsSource = TreeViewList;
        }
コード例 #2
0
        //返回List<RuleItem>,用作显示在检查工具中
        public List <RuleItem> parseDelivery()
        {
            Initialize();

            int             firstClass    = 0;
            int             secondClass   = 0;
            int             thirdClass    = 0;
            RuleItem        curFirstRule  = null;
            RuleItem        curSecondRule = null;
            List <RuleItem> allRules      = new List <RuleItem>();

            do
            {
                //对于每一行
                while (excelInfo.Read())
                {
                    //跳过第一列有值的行
                    if (excelInfo.GetValue(0) != null)
                    {
                        continue;
                    }

                    //如果第二列有值
                    if (excelInfo.GetValue(1) != null)
                    {
                        firstClass++;
                        secondClass = 0;

                        string name = firstClass.ToString() + ':' + excelInfo.GetValue(1).ToString();
                        //Console.WriteLine(name);

                        curFirstRule      = new RuleItem(name);
                        curFirstRule.Text = excelInfo.GetValue(1).ToString();
                        allRules.Add(curFirstRule);
                    }

                    //如果第三列有值
                    if (excelInfo.GetValue(2) != null)
                    {
                        secondClass++;
                        thirdClass = 0;

                        string name = firstClass.ToString() + '.' + secondClass.ToString() + ':' + excelInfo.GetValue(2).ToString();
                        curSecondRule      = new RuleItem(name);
                        curSecondRule.Text = excelInfo.GetValue(2).ToString();

                        curFirstRule.Children.Add(curSecondRule);
                        //Console.WriteLine(name);
                    }

                    //如果第四列有值
                    if (excelInfo.GetValue(3) != null)
                    {
                        thirdClass++;
                        string name      = firstClass.ToString() + '.' + secondClass.ToString() + '.' + thirdClass.ToString() + ':' + excelInfo.GetValue(3).ToString();
                        var    thirdRule = new RuleItem(name);
                        curSecondRule.Children.Add(thirdRule);
                        //Console.WriteLine(name);
                    }
                }
            } while (excelInfo.NextResult());

            foreach (var rule in allRules)
            {
                rule.Initialize();
            }

            return(allRules);
        }