Beispiel #1
0
        public static List <MiMFa_XMLElement> GetFrom(List <MiMFa_XMLElement> inThisList, MiMFa_XMLElement fromThisElement)
        {
            int ind = -1;

            for (int i = 0; i < inThisList.Count; i++)
            {
                if (inThisList[i] <= fromThisElement)
                {
                    ind = i;
                }
                else
                {
                    break;
                }
            }
            if (ind < 0)
            {
                return(inThisList);
            }
            MiMFa_XMLElement m = inThisList.Last();

            if (!fromThisElement.ID.StartsWith(m.ID) && m < fromThisElement)
            {
                return(new List <MiMFa_XMLElement>());
            }
            inThisList[ind].Children = GetFrom(inThisList[ind].Children, fromThisElement);
            return(MiMFa_CollectionService.GetPart(inThisList, ind));
        }
Beispiel #2
0
 public static bool IsSame(MiMFa_XMLElement thisElement, MiMFa_XMLElement withThisElement)
 {
     if (thisElement == null && withThisElement == null)
     {
         return(true);
     }
     try
     {
         bool b = thisElement.TagName == withThisElement.TagName &&
                  IsCongruent(thisElement.Parent, withThisElement.Parent);
         if (b)
         {
             var th  = thisElement.Attributes;
             var wth = withThisElement.Attributes;
             b = th.Count == wth.Count;
             if (b)
             {
                 foreach (var item in wth)
                 {
                     try
                     {
                         b = item.Value == th[item.Key];
                         if (!b)
                         {
                             return(false);
                         }
                     }
                     catch { return(false); }
                 }
             }
         }
         return(b);
     }
     catch { return(false); }
 }
Beispiel #3
0
 public List <MiMFa_XMLElement> GetTo(MiMFa_XMLElement toThisElement)
 {
     return(GetTo(new List <MiMFa_XMLElement>()
     {
         this
     }, toThisElement));
 }
Beispiel #4
0
        public static MiMFa_XMLElement Find(MiMFa_XMLElement inThisElement, MiMFa_XMLElement xmlPatern)
        {
            MiMFa_XMLElement elem = inThisElement.GetElementByID(xmlPatern.ID);

            if (elem == null || (elem != null && !elem.IsSame(xmlPatern)))
            {
                List <MiMFa_XMLElement> ls = inThisElement.GetElementsByParentID(xmlPatern.ParentID) ?? new List <MiMFa_XMLElement>();
                for (int i = 0; i < ls.Count; i++)
                {
                    if (ls[i].IsSame(xmlPatern))
                    {
                        return(ls[i]);
                    }
                }
                if ((elem = FindDuplicate(inThisElement, xmlPatern)) != null)
                {
                    return(elem);
                }
                if ((elem = FindSame(inThisElement, xmlPatern)) != null)
                {
                    return(elem);
                }
                if ((elem = FindLike(inThisElement, xmlPatern)) != null)
                {
                    return(elem);
                }
            }
            return(elem);
        }
Beispiel #5
0
 public static bool IsCongruent(MiMFa_XMLElement thisElement, MiMFa_XMLElement withThisElement)
 {
     if (thisElement == null && withThisElement == null)
     {
         return(true);
     }
     if (thisElement == null || withThisElement == null)
     {
         return(false);
     }
     try
     {
         bool b = thisElement.TagName == withThisElement.TagName;
         if (b)
         {
             var th  = thisElement.Attributes;
             var wth = withThisElement.Attributes;
             if (b)
             {
                 foreach (var item in wth)
                 {
                     try { string s = th[item.Key]; } catch { return(false); }
                 }
             }
         }
         return(b);
     }catch { return(false); }
 }
Beispiel #6
0
 public static List <MiMFa_XMLElement> GetElementsByParentID(MiMFa_XMLElement element, string id)
 {
     return(GetElementsByParentID(new List <MiMFa_XMLElement>()
     {
         element
     }, id));
 }
Beispiel #7
0
 public static List <MiMFa_XMLElement> GetElementsByTagName(MiMFa_XMLElement element, string tagName)
 {
     return(GetElementsByTagName(new List <MiMFa_XMLElement>()
     {
         element
     }, tagName));
 }
Beispiel #8
0
 public static MiMFa_XMLElement GetElementByID(MiMFa_XMLElement element, string id)
 {
     return(GetElementByID(new List <MiMFa_XMLElement>()
     {
         element
     }, id));
 }
Beispiel #9
0
 public static MiMFa_XMLElement GetElementsCommonParent(List <MiMFa_XMLElement> elements)
 {
     if (elements != null && elements.Count > 0)
     {
         MiMFa_XMLElement cf = elements.First();
         MiMFa_XMLElement cl = elements.Last();
         if (cf.ID.StartsWith(cl.ID))
         {
             return(cl);
         }
         if (cl.ID.StartsWith(cf.ID))
         {
             return(cf);
         }
         while (cf.Parent != null && cl.Parent != null)
         {
             cf = cf.Parent;
             if (cl.ID.StartsWith(cf.ID))
             {
                 return(cf);
             }
             cl = cl.Parent;
             if (cf.ID.StartsWith(cl.ID))
             {
                 return(cl);
             }
         }
     }
     return(null);
 }
Beispiel #10
0
 public List <MiMFa_XMLElement> GetFrom(MiMFa_XMLElement fromThisElement)
 {
     return(GetFrom(new List <MiMFa_XMLElement>()
     {
         this
     }, fromThisElement));
 }
Beispiel #11
0
        public static string GetAttributes(MiMFa_XMLElement thisElement, string name)
        {
            Dictionary <string, string> dic = thisElement.Attributes;

            try { return(dic[name.Trim()]); }
            catch { return(""); }
        }
Beispiel #12
0
 public static MiMFa_XMLElement Find(MiMFa_XMLElement inThisElement, string search)
 {
     if (inThisElement.StartTag.ToLower().Contains(search.ToLower()))
     {
         return(inThisElement);
     }
     return(Find(inThisElement.Children, search));
 }
Beispiel #13
0
 public MiMFa_XMLElement(int index = 0, string tagName = "", string startTag = "", string endTag = "", Dictionary <string, string> attribute = null, MiMFa_XMLElement parent = null)
 {
     TagName     = tagName;
     StartTag    = startTag;
     EndTag      = endTag;
     Parent      = parent;
     Index       = index;
     _Attributes = attribute;
 }
Beispiel #14
0
        public static MiMFa_XMLElement Find(List <MiMFa_XMLElement> inThisList, string search)
        {
            MiMFa_XMLElement elem = null;

            for (int i = 0; i < inThisList.Count && elem == null; i++)
            {
                elem = Find(inThisList[i], search);
            }
            return(elem);
        }
Beispiel #15
0
        public static List <MiMFa_XMLElement> GetAllChildren(MiMFa_XMLElement element)
        {
            List <MiMFa_XMLElement> le = new List <MiMFa_XMLElement>();

            le.AddRange(element.Children);
            for (int i = 0; i < element.Children.Count; i++)
            {
                le.AddRange(GetAllChildren(element.Children[i]));
            }
            return(le);
        }
Beispiel #16
0
        public static List <MiMFa_XMLElement> FindList(MiMFa_XMLElement inThisElement, string search)
        {
            List <MiMFa_XMLElement> ls = new List <MiMFa_XMLElement>();

            if (inThisElement.StartTag.ToLower().Contains(search.ToLower()))
            {
                ls.Add(inThisElement);
            }
            ls.AddRange(FindList(inThisElement.Children, search));
            return(ls);
        }
Beispiel #17
0
 public static MiMFa_XMLElement GetFirstChildElementByTagName(MiMFa_XMLElement element, string tagName)
 {
     tagName = tagName.Trim().ToUpper();
     for (int i = 0; i < element.Children.Count; i++)
     {
         if (element.Children[i].TagName == tagName)
         {
             return(element.Children[i]);
         }
     }
     return(null);
 }
Beispiel #18
0
 public static bool IsThis(MiMFa_XMLElement thisElement, MiMFa_XMLElement withThisElement)
 {
     if (thisElement == null && withThisElement == null)
     {
         return(true);
     }
     try
     {
         return(thisElement.ID == withThisElement.ID &&
                IsDuplicate(thisElement, withThisElement));
     }catch { return(false); }
 }
Beispiel #19
0
 public MiMFa_XMLElement(MiMFa_XMLElement elem)
 {
     _Attributes      = elem._Attributes;
     _NestedNumber    = elem._NestedNumber;
     _NestedTag       = elem._NestedTag;
     _ParentNestedTag = elem._ParentNestedTag;
     TagName          = elem.TagName;
     StartTag         = elem.StartTag;
     EndTag           = elem.EndTag;
     Parent           = elem.Parent;
     Index            = elem.Index;
     Children         = GetCopy(elem.Children);
 }
Beispiel #20
0
        public static MiMFa_XMLElement Find(List <MiMFa_XMLElement> inThisList, MiMFa_XMLElement xmlPatern)
        {
            MiMFa_XMLElement elem = null;

            for (int i = 0; i < inThisList.Count; i++)
            {
                if ((elem = Find(inThisList[i], xmlPatern)) != null)
                {
                    return(elem);
                }
            }
            return(null);
        }
Beispiel #21
0
        public static List <MiMFa_XMLElement> FindList(MiMFa_XMLElement inThisElement, MiMFa_XMLElement xmlPatern)
        {
            List <MiMFa_XMLElement> lsr = new List <MiMFa_XMLElement>();
            List <MiMFa_XMLElement> ls  = inThisElement.GetElementsByParentID(xmlPatern.ParentID) ?? new List <MiMFa_XMLElement>();

            for (int i = 0; i < ls.Count; i++)
            {
                if (ls[i].IsSame(xmlPatern))
                {
                    lsr.Add(ls[i]);
                }
            }
            return(lsr);
        }
Beispiel #22
0
        public static List <MiMFa_XMLElement> GetChildElementsByTagName(MiMFa_XMLElement element, string tagName)
        {
            tagName = tagName.Trim().ToUpper();
            List <MiMFa_XMLElement> ls = new List <MiMFa_XMLElement>();

            for (int i = 0; i < element.Children.Count; i++)
            {
                if (element.Children[i].TagName == tagName)
                {
                    ls.Add(element.Children[i]);
                }
            }
            return(ls);
        }
Beispiel #23
0
        private List <string> GetChildAttributes(MiMFa_XMLElement miMFa_XMLElement, string name)
        {
            List <string> ls  = new List <string>();
            string        str = "";

            foreach (var item in miMFa_XMLElement.Children)
            {
                if (!string.IsNullOrEmpty(str = item.GetAttribute(name)))
                {
                    ls.Add(str);
                }
            }
            return(ls);
        }
Beispiel #24
0
        public static MiMFa_XMLElement FindCongruent(MiMFa_XMLElement inThisElement, MiMFa_XMLElement xmlPatern)
        {
            MiMFa_XMLElement elem = IsCongruent(inThisElement, xmlPatern) ? inThisElement : null;

            if (elem == null)
            {
                for (int i = 0; i < inThisElement.Children.Count; i++)
                {
                    if ((elem = FindCongruent(inThisElement.Children[i], xmlPatern)) != null)
                    {
                        return(elem);
                    }
                }
            }
            return(elem);
        }
Beispiel #25
0
        public void RefreshNested()
        {
            MiMFa_XMLElement elem = this;

            _NestedNumber    = 1;
            _NestedTag       = elem.TagName;
            _ParentNestedTag = "";
            while (elem.Parent != null)
            {
                elem = elem.Parent;
                _NestedNumber++;
                _NestedTag       = string.Join("-", elem.TagName, _NestedTag);
                _ParentNestedTag = string.Join("-", elem.TagName, _ParentNestedTag);
            }
            _ParentNestedTag = _ParentNestedTag.TrimEnd('-');
        }
Beispiel #26
0
        public MiMFa_XMLElement(string ID)
        {
            var sa  = MiMFa_StringService.LastFindAndSplit(ID, "-");
            int num = ID.Split('-').Length;

            TagName  = "";
            StartTag = "";
            EndTag   = "";
            Index    = MiMFa_Convert.TryToInt(sa.Last(), 0);
            if (num > 2)
            {
                Parent = new MiMFa_XMLElement(sa.First());
            }
            else
            {
                Parent = null;
            }
        }
Beispiel #27
0
        public static MiMFa_XMLElement GetFirstElementByTagName(List <MiMFa_XMLElement> elements, string tagName)
        {
            tagName = tagName.ToUpper();
            MiMFa_XMLElement he = null;

            for (int i = 0; i < elements.Count; i++)
            {
                if (elements[i].TagName == tagName)
                {
                    return(elements[i]);
                }
                else if ((he = GetFirstElementByTagName(elements[i].Children, tagName)) != null)
                {
                    return(he);
                }
            }
            return(null);
        }
Beispiel #28
0
        public static bool RemoveFirstElementByTagName(List <MiMFa_XMLElement> elements, string tagName)
        {
            tagName = tagName.ToUpper();
            MiMFa_XMLElement he = null;

            for (int i = 0; i < elements.Count; i++)
            {
                if (elements[i].TagName == tagName)
                {
                    elements.RemoveAt(i); return(true);
                }
                else if (RemoveFirstElementByTagName(elements[i].Children, tagName))
                {
                    return(true);
                }
            }
            return(false);
        }
Beispiel #29
0
        public static MiMFa_XMLElement GetElementByID(List <MiMFa_XMLElement> elements, string id)
        {
            MiMFa_XMLElement he = null;

            for (int i = 0; i < elements.Count; i++)
            {
                if (id.StartsWith(elements[i].ID))
                {
                    if (id == elements[i].ID)
                    {
                        return(elements[i]);
                    }
                    else if ((he = GetElementByID(elements[i].Children, id)) != null)
                    {
                        return(he);
                    }
                }
            }
            return(null);
        }
Beispiel #30
0
        public static List <MiMFa_XMLElement> FindCongruentList(MiMFa_XMLElement inThisElement, MiMFa_XMLElement xmlPatern)
        {
            List <MiMFa_XMLElement> lsr = new List <MiMFa_XMLElement>();
            List <MiMFa_XMLElement> lsm = new List <MiMFa_XMLElement>();

            if (IsCongruent(inThisElement, xmlPatern))
            {
                lsr.Add(inThisElement);
            }
            else
            {
                for (int i = 0; i < inThisElement.Children.Count; i++)
                {
                    if ((lsm = FindCongruentList(inThisElement.Children[i], xmlPatern)).Count > 0)
                    {
                        lsr.AddRange(lsm);
                    }
                }
            }
            return(lsr);
        }