예제 #1
0
        public void FindRecursiveDatas(XmlDocument document)
        {
            List <XmlNode> recursiveFields = FindOuterRecursives(document);

            if (recursiveFields != null)
            {
                int recursiveFieldIndex = 0;
                Console.WriteLine("######NUMBER:::### {0}", recursiveFields.Count);
                foreach (XmlNode node in recursiveFields)
                {
                    RecursiveDatas.Add(new RecursiveData(node.Name));

                    foreach (XmlNode child in node.ChildNodes)
                    {
                        if (child.Name.StartsWith("F_"))
                        {
                            if (child.Attributes[0].Value == "CHR")
                            {
                                KeyValuePair <string, string> temp = new KeyValuePair <string, string>(child.Name, child.InnerText);
                                RecursiveDatas[recursiveFieldIndex].AddData(new FieldData(child.Name, temp));
                                Console.WriteLine("{0} {1} was added!", child.Name, child.InnerText);
                            }
                            else if (child.Attributes[0].Value == "DAT")
                            {
                                KeyValuePair <string, string> temp = new KeyValuePair <string, string>(child.Name, child.Attributes[1].Value);
                                RecursiveDatas[recursiveFieldIndex].AddData(new FieldData(child.Name, temp));
                                Console.WriteLine("{0} {1} was added!", child.Name, child.InnerText);
                            }
                        }
                        else if (child.Name.StartsWith("G_"))
                        {
                            GroupData temp = new GroupData(child.Name);
                            foreach (XmlNode childChild in child.ChildNodes)
                            {
                                if (childChild.Name.StartsWith("F_"))
                                {
                                    if (childChild.Attributes[0].Value == "CHR")
                                    {
                                        KeyValuePair <string, string> tempDic = new KeyValuePair <string, string>(childChild.Name, childChild.InnerText);
                                        Console.WriteLine("childChild {0} ", childChild.InnerText);
                                        temp.AddData(new FieldData(childChild.Name, tempDic));
                                        Console.WriteLine("{0} {1} was added!", childChild.Name, childChild.InnerText);
                                    }
                                    else if (child.Attributes[0].Value == "DAT")
                                    {
                                        KeyValuePair <string, string> tempDic = new KeyValuePair <string, string>(childChild.Name, childChild.Attributes[1].Value);
                                        temp.AddData(new FieldData(childChild.Name, tempDic));
                                        Console.WriteLine("{0} {1} was added!", childChild.Name, childChild.InnerText);
                                    }
                                }
                            }
                            RecursiveDatas[recursiveFieldIndex].AddData(temp);
                        }
                        else
                        {
                            List <BaseData> baseDatas = FindDataInsideRecursive(child);
                            RecursiveData   recData   = new RecursiveData(child.Name);
                            foreach (var baseData in baseDatas)
                            {
                                recData.AddData(baseData);
                            }
                            RecursiveDatas[recursiveFieldIndex].AddData(recData);
                        }
                    }
                    recursiveFieldIndex++;
                }
            }
        }
예제 #2
0
        //Ez az algoritmus még messze nem jó, javításra szorul
        //Megnézzük, hogy van-e R_* a rekurzívak között
        //Ha nincs -> Visszaadjuk a tageket és jók vagyunk

        /*
         * Ha van, akkor az adott fieldre megnézzük, hogy hány R_* van még alatta
         * ezt eltároljuk és egy while ciklussal addig megyünk, amíg ki nem gyüjtjük az összeset
         */
        private List <BaseData> FindDataInsideRecursive(XmlNode recNode)
        {
            List <BaseData> baseDatas = new List <BaseData>();

            foreach (XmlNode node in recNode)
            {
                if (node.Name.StartsWith("F_"))
                {
                    if (node.Attributes[0].Value == "CHR")
                    {
                        baseDatas.Add(new FieldData(new KeyValuePair <string, string>(node.Name, node.InnerText)));
                    }
                    else if (node.Attributes[0].Value == "DAT")
                    {
                        baseDatas.Add(new FieldData(new KeyValuePair <string, string>(node.Name, node.Attributes[1].Value)));
                    }
                }
                else if (node.Name.StartsWith("G_"))
                {
                    GroupData temp = new GroupData(node.Name);
                    foreach (XmlNode child in node.ChildNodes)
                    {
                        if (child.Name.StartsWith("F_"))
                        {
                            if (child.Attributes[0].Value == "CHR")
                            {
                                temp.AddData(new FieldData(new KeyValuePair <string, string>(child.Name, child.InnerText)));
                            }
                            else if (child.Attributes[0].Value == "DAT")
                            {
                                temp.AddData(new FieldData(new KeyValuePair <string, string>(child.Name, child.Attributes[1].Value)));
                            }
                        }
                    }
                    baseDatas.Add(temp);
                }
                else
                {
                    RecursiveData recData = new RecursiveData(node.Name);
                    XmlNodeList   childs  = node.ChildNodes;
                    while (childs != null)
                    {
                        foreach (XmlNode child in childs)
                        {
                            if (child.Name.StartsWith("F_"))
                            {
                                if (child.Attributes[0].Value == "CHR")
                                {
                                    recData.AddData(new FieldData(new KeyValuePair <string, string>(node.Name, node.InnerText)));
                                }
                                else if (node.Attributes[0].Value == "DAT")
                                {
                                    recData.AddData(new FieldData(new KeyValuePair <string, string>(node.Name, node.Attributes[1].Value)));
                                }
                            }
                            else if (node.Name.StartsWith("G_"))
                            {
                                GroupData tempGroup = new GroupData(child.Name);
                                foreach (XmlNode groupChild in child.ChildNodes)
                                {
                                    if (groupChild.Name.StartsWith("F_"))
                                    {
                                        if (groupChild.Attributes[0].Value == "CHR")
                                        {
                                            tempGroup.AddData(new FieldData(new KeyValuePair <string, string>(groupChild.Name, groupChild.InnerText)));
                                        }
                                        else if (child.Attributes[0].Value == "DAT")
                                        {
                                            tempGroup.AddData(new FieldData(new KeyValuePair <string, string>(groupChild.Name, groupChild.Attributes[1].Value)));
                                        }
                                    }
                                }
                                recData.AddData(tempGroup);
                            }
                            else
                            {
                                RecursiveData temp = new RecursiveData(child.Name);
                                recData.AddData(temp);
                                if (child.ChildNodes.Count == 0)
                                {
                                    childs = null;
                                }
                                else
                                {
                                    childs = child.ChildNodes;
                                }
                            }
                        }
                    }
                    baseDatas.Add(recData);
                }
            }
            return(baseDatas);
        }