Beispiel #1
0
 private static void RecursiveNodeCopyOverwriteElements(XmlNode source, XmlNode target)
 {
     if (source.ChildNodes.Count == 0)
     {
         while (target.HasChildNodes)
         {
             target.RemoveChild(target.FirstChild);
         }
     }
     if (source.ChildNodes.Count == 1 && source.FirstChild.NodeType == XmlNodeType.Text)
     {
         while (target.HasChildNodes)
         {
             target.RemoveChild(target.FirstChild);
         }
         XmlNode newChild = target.OwnerDocument.ImportNode(source.FirstChild, true);
         target.AppendChild(newChild);
     }
     else
     {
         IEnumerator enumerator = source.GetEnumerator();
         try
         {
             while (enumerator.MoveNext())
             {
                 XmlNode xmlNode = (XmlNode)enumerator.Current;
                 if (xmlNode.Name == "li")
                 {
                     XmlNode newChild2 = target.OwnerDocument.ImportNode(xmlNode, true);
                     target.AppendChild(newChild2);
                 }
                 else
                 {
                     XmlElement xmlElement = target[xmlNode.Name];
                     if (xmlElement != null)
                     {
                         XmlInheritance.RecursiveNodeCopyOverwriteElements(xmlNode, xmlElement);
                     }
                     else
                     {
                         XmlNode newChild3 = target.OwnerDocument.ImportNode(xmlNode, true);
                         target.AppendChild(newChild3);
                     }
                 }
             }
         }
         finally
         {
             IDisposable disposable;
             if ((disposable = (enumerator as IDisposable)) != null)
             {
                 disposable.Dispose();
             }
         }
     }
 }
Beispiel #2
0
 private static void RecursiveNodeCopyOverwriteElements(XmlNode source, XmlNode target)
 {
     if (source.ChildNodes.Count == 0)
     {
         while (target.HasChildNodes)
         {
             target.RemoveChild(target.FirstChild);
         }
     }
     if (source.ChildNodes.Count == 1 && source.FirstChild.NodeType == XmlNodeType.Text)
     {
         while (target.HasChildNodes)
         {
             target.RemoveChild(target.FirstChild);
         }
         XmlNode newChild = target.OwnerDocument.ImportNode(source.FirstChild, true);
         target.AppendChild(newChild);
     }
     else
     {
         foreach (XmlNode xmlNode in source)
         {
             if (xmlNode.Name == "li")
             {
                 XmlNode newChild2 = target.OwnerDocument.ImportNode(xmlNode, true);
                 target.AppendChild(newChild2);
             }
             else
             {
                 XmlElement xmlElement = target[xmlNode.Name];
                 if (xmlElement != null)
                 {
                     XmlInheritance.RecursiveNodeCopyOverwriteElements(xmlNode, xmlElement);
                 }
                 else
                 {
                     XmlNode newChild3 = target.OwnerDocument.ImportNode(xmlNode, true);
                     target.AppendChild(newChild3);
                 }
             }
         }
     }
 }
Beispiel #3
0
        private static void ResolveXmlNodeFor(XmlInheritance.XmlInheritanceNode node)
        {
            if (node.parent == null)
            {
                node.resolvedXmlNode = node.xmlNode;
                return;
            }
            if (node.parent.resolvedXmlNode == null)
            {
                Log.Error("XML error: Internal error. Tried to resolve node whose parent has not been resolved yet. This means that this method was called in incorrect order.");
                node.resolvedXmlNode = node.xmlNode;
                return;
            }
            XmlInheritance.CheckForDuplicateNodes(node.xmlNode);
            XmlNode xmlNode = node.parent.resolvedXmlNode.CloneNode(true);

            xmlNode.Attributes.RemoveAll();
            XmlAttributeCollection attributes = node.xmlNode.Attributes;

            for (int i = 0; i < attributes.Count; i++)
            {
                if (!(attributes[i].Name == XmlInheritance.NameAttributeName) && !(attributes[i].Name == XmlInheritance.ParentNameAttributeName))
                {
                    XmlAttribute node2 = (XmlAttribute)xmlNode.OwnerDocument.ImportNode(attributes[i], true);
                    xmlNode.Attributes.Append(node2);
                }
            }
            XmlAttributeCollection attributes2 = node.parent.resolvedXmlNode.Attributes;

            for (int j = 0; j < attributes2.Count; j++)
            {
                if (!(attributes2[j].Name == XmlInheritance.NameAttributeName) && !(attributes2[j].Name == XmlInheritance.ParentNameAttributeName))
                {
                    if (xmlNode.Attributes[attributes2[j].Name] == null)
                    {
                        XmlAttribute node3 = (XmlAttribute)xmlNode.OwnerDocument.ImportNode(attributes2[j], true);
                        xmlNode.Attributes.Append(node3);
                    }
                }
            }
            XmlInheritance.RecursiveNodeCopyOverwriteElements(node.xmlNode, xmlNode);
            node.resolvedXmlNode = xmlNode;
        }
Beispiel #4
0
        private static void ResolveXmlNodeFor(XmlInheritance.XmlInheritanceNode node)
        {
            if (node.parent == null)
            {
                node.resolvedXmlNode = node.xmlNode;
                return;
            }
            if (node.parent.resolvedXmlNode == null)
            {
                Log.Error("XML error: Internal error. Tried to resolve node whose parent has not been resolved yet. This means that this method was called in incorrect order.", false);
                node.resolvedXmlNode = node.xmlNode;
                return;
            }
            XmlInheritance.CheckForDuplicateNodes(node.xmlNode, node.xmlNode);
            XmlNode xmlNode = node.parent.resolvedXmlNode.CloneNode(true);

            XmlInheritance.RecursiveNodeCopyOverwriteElements(node.xmlNode, xmlNode);
            node.resolvedXmlNode = xmlNode;
        }
Beispiel #5
0
        private static void RecursiveNodeCopyOverwriteElements(XmlNode child, XmlNode current)
        {
            XmlAttribute xmlAttribute = child.Attributes["Inherit"];

            if (xmlAttribute != null && xmlAttribute.Value.ToLower() == "false")
            {
                while (current.HasChildNodes)
                {
                    current.RemoveChild(current.FirstChild);
                }
                IEnumerator enumerator = child.GetEnumerator();
                try
                {
                    while (enumerator.MoveNext())
                    {
                        object  obj      = enumerator.Current;
                        XmlNode node     = (XmlNode)obj;
                        XmlNode newChild = current.OwnerDocument.ImportNode(node, true);
                        current.AppendChild(newChild);
                    }
                }
                finally
                {
                    IDisposable disposable;
                    if ((disposable = (enumerator as IDisposable)) != null)
                    {
                        disposable.Dispose();
                    }
                }
                return;
            }
            current.Attributes.RemoveAll();
            XmlAttributeCollection attributes = child.Attributes;

            for (int i = 0; i < attributes.Count; i++)
            {
                XmlAttribute node2 = (XmlAttribute)current.OwnerDocument.ImportNode(attributes[i], true);
                current.Attributes.Append(node2);
            }
            List <XmlElement> list        = new List <XmlElement>();
            XmlNode           xmlNode     = null;
            IEnumerator       enumerator2 = child.GetEnumerator();

            try
            {
                while (enumerator2.MoveNext())
                {
                    object  obj2     = enumerator2.Current;
                    XmlNode xmlNode2 = (XmlNode)obj2;
                    if (xmlNode2.NodeType == XmlNodeType.Text)
                    {
                        xmlNode = xmlNode2;
                    }
                    else if (xmlNode2.NodeType == XmlNodeType.Element)
                    {
                        list.Add((XmlElement)xmlNode2);
                    }
                }
            }
            finally
            {
                IDisposable disposable2;
                if ((disposable2 = (enumerator2 as IDisposable)) != null)
                {
                    disposable2.Dispose();
                }
            }
            if (xmlNode != null)
            {
                for (int j = current.ChildNodes.Count - 1; j >= 0; j--)
                {
                    XmlNode xmlNode3 = current.ChildNodes[j];
                    if (xmlNode3.NodeType != XmlNodeType.Attribute)
                    {
                        current.RemoveChild(xmlNode3);
                    }
                }
                XmlNode newChild2 = current.OwnerDocument.ImportNode(xmlNode, true);
                current.AppendChild(newChild2);
            }
            else if (!list.Any <XmlElement>())
            {
                bool        flag        = false;
                IEnumerator enumerator3 = current.ChildNodes.GetEnumerator();
                try
                {
                    while (enumerator3.MoveNext())
                    {
                        object  obj3     = enumerator3.Current;
                        XmlNode xmlNode4 = (XmlNode)obj3;
                        if (xmlNode4.NodeType == XmlNodeType.Element)
                        {
                            flag = true;
                            break;
                        }
                    }
                }
                finally
                {
                    IDisposable disposable3;
                    if ((disposable3 = (enumerator3 as IDisposable)) != null)
                    {
                        disposable3.Dispose();
                    }
                }
                if (!flag)
                {
                    IEnumerator enumerator4 = current.ChildNodes.GetEnumerator();
                    try
                    {
                        while (enumerator4.MoveNext())
                        {
                            object  obj4     = enumerator4.Current;
                            XmlNode xmlNode5 = (XmlNode)obj4;
                            if (xmlNode5.NodeType != XmlNodeType.Attribute)
                            {
                                current.RemoveChild(xmlNode5);
                            }
                        }
                    }
                    finally
                    {
                        IDisposable disposable4;
                        if ((disposable4 = (enumerator4 as IDisposable)) != null)
                        {
                            disposable4.Dispose();
                        }
                    }
                }
            }
            else
            {
                for (int k = 0; k < list.Count; k++)
                {
                    XmlElement xmlElement = list[k];
                    if (xmlElement.Name == "li")
                    {
                        XmlNode newChild3 = current.OwnerDocument.ImportNode(xmlElement, true);
                        current.AppendChild(newChild3);
                    }
                    else
                    {
                        XmlElement xmlElement2 = current[xmlElement.Name];
                        if (xmlElement2 != null)
                        {
                            XmlInheritance.RecursiveNodeCopyOverwriteElements(xmlElement, xmlElement2);
                        }
                        else
                        {
                            XmlNode newChild4 = current.OwnerDocument.ImportNode(xmlElement, true);
                            current.AppendChild(newChild4);
                        }
                    }
                }
            }
        }
Beispiel #6
0
        private static void RecursiveNodeCopyOverwriteElements(XmlNode child, XmlNode current)
        {
            XmlAttribute xmlAttribute = child.Attributes["Inherit"];

            if (xmlAttribute != null && xmlAttribute.Value.ToLower() == "false")
            {
                while (current.HasChildNodes)
                {
                    current.RemoveChild(current.FirstChild);
                }
                foreach (XmlNode node in child)
                {
                    XmlNode newChild = current.OwnerDocument.ImportNode(node, true);
                    current.AppendChild(newChild);
                }
                return;
            }
            current.Attributes.RemoveAll();
            XmlAttributeCollection attributes = child.Attributes;

            for (int i = 0; i < attributes.Count; i++)
            {
                XmlAttribute node2 = (XmlAttribute)current.OwnerDocument.ImportNode(attributes[i], true);
                current.Attributes.Append(node2);
            }
            List <XmlElement> list    = new List <XmlElement>();
            XmlNode           xmlNode = null;

            foreach (XmlNode xmlNode2 in child)
            {
                if (xmlNode2.NodeType == XmlNodeType.Text)
                {
                    xmlNode = xmlNode2;
                }
                else if (xmlNode2.NodeType == XmlNodeType.Element)
                {
                    list.Add((XmlElement)xmlNode2);
                }
            }
            if (xmlNode != null)
            {
                for (int j = current.ChildNodes.Count - 1; j >= 0; j--)
                {
                    XmlNode xmlNode3 = current.ChildNodes[j];
                    if (xmlNode3.NodeType != XmlNodeType.Attribute)
                    {
                        current.RemoveChild(xmlNode3);
                    }
                }
                XmlNode newChild2 = current.OwnerDocument.ImportNode(xmlNode, true);
                current.AppendChild(newChild2);
            }
            else if (!list.Any <XmlElement>())
            {
                bool flag = false;
                foreach (XmlNode xmlNode4 in current.ChildNodes)
                {
                    if (xmlNode4.NodeType == XmlNodeType.Element)
                    {
                        flag = true;
                        break;
                    }
                }
                if (!flag)
                {
                    foreach (XmlNode xmlNode5 in current.ChildNodes)
                    {
                        if (xmlNode5.NodeType != XmlNodeType.Attribute)
                        {
                            current.RemoveChild(xmlNode5);
                        }
                    }
                }
            }
            else
            {
                for (int k = 0; k < list.Count; k++)
                {
                    XmlElement xmlElement = list[k];
                    if (xmlElement.Name == "li")
                    {
                        XmlNode newChild3 = current.OwnerDocument.ImportNode(xmlElement, true);
                        current.AppendChild(newChild3);
                    }
                    else
                    {
                        XmlElement xmlElement2 = current[xmlElement.Name];
                        if (xmlElement2 != null)
                        {
                            XmlInheritance.RecursiveNodeCopyOverwriteElements(xmlElement, xmlElement2);
                        }
                        else
                        {
                            XmlNode newChild4 = current.OwnerDocument.ImportNode(xmlElement, true);
                            current.AppendChild(newChild4);
                        }
                    }
                }
            }
        }