コード例 #1
0
 internal void InsertAttributeAfter(XmlDiffAttribute attr, XmlDiffAttribute newAttr)
 {
     Debug.Assert(newAttr != null);
     newAttr._ownerElement = this;
     if (attr == null)
     {
         newAttr._next   = _firstAttribute;
         _firstAttribute = newAttr;
     }
     else
     {
         Debug.Assert(attr._ownerElement == this);
         newAttr._next = attr._next;
         attr._next    = newAttr;
     }
     if (newAttr._next == null)
     {
         _lastAttribute = newAttr;
     }
 }
コード例 #2
0
 //sunghonhack
 public new bool MoveToFirstNamespace()
 {
     if (_currentNode is XmlDiffElement)
     {
         if (((XmlDiffElement)_currentNode).FirstAttribute != null)
         {
             XmlDiffAttribute _attr = ((XmlDiffElement)_currentNode).FirstAttribute;
             while (_attr != null && !IsNamespaceNode(_attr))
             {
                 _attr = (XmlDiffAttribute)_attr._next;
             }
             if (_attr != null)
             {
                 _currentNode = _attr;
                 return(true);
             }
         }
     }
     return(false);
 }
コード例 #3
0
 private void InsertAttribute(XmlDiffElement parent, XmlDiffAttribute newAttr)
 {
     Debug.Assert(parent != null);
     Debug.Assert(newAttr != null);
     newAttr._parent = parent;
     if (IgnoreAttributeOrder)
     {
         XmlDiffAttribute attr     = parent.FirstAttribute;
         XmlDiffAttribute prevAttr = null;
         while (attr != null && (CompareAttributes(attr, newAttr) == NodePosition.After))
         {
             prevAttr = attr;
             attr     = (XmlDiffAttribute)(attr.NextSibling);
         }
         parent.InsertAttributeAfter(prevAttr, newAttr);
     }
     else
     {
         parent.InsertAttributeAfter(parent.LastAttribute, newAttr);
     }
 }
コード例 #4
0
 private bool IsNamespaceNode(XmlDiffAttribute attr)
 {
     return(attr.LocalName.ToLowerInvariant() == "xmlns" ||
            attr.Prefix.ToLowerInvariant() == "xmlns");
 }
コード例 #5
0
        // This function is used to compare the attributes of an element node according to the options set by the user.
        private bool CompareAttributes(XmlDiffElement sourceElem, XmlDiffElement targetElem)
        {
            Debug.Assert(sourceElem != null);
            Debug.Assert(targetElem != null);
            if (sourceElem.AttributeCount != targetElem.AttributeCount && !IgnoreNS)
            {
                return(false);
            }

            if (sourceElem.AttributeCount == 0)
            {
                return(true);
            }

            XmlDiffAttribute sourceAttr = sourceElem.FirstAttribute;
            XmlDiffAttribute targetAttr = targetElem.FirstAttribute;

            const string xmlnsNamespace = "http://www.w3.org/2000/xmlns/";

            if (!IgnoreAttributeOrder)
            {
                while (sourceAttr != null && targetAttr != null)
                {
                    if (!IgnoreNS)
                    {
                        if (sourceAttr.NamespaceURI != targetAttr.NamespaceURI)
                        {
                            return(false);
                        }
                    }

                    if (!IgnorePrefix)
                    {
                        if (sourceAttr.Prefix != targetAttr.Prefix)
                        {
                            return(false);
                        }
                    }

                    if (sourceAttr.NamespaceURI == xmlnsNamespace && targetAttr.NamespaceURI == xmlnsNamespace)
                    {
                        if (!IgnorePrefix && (sourceAttr.LocalName != targetAttr.LocalName))
                        {
                            return(false);
                        }
                        if (!IgnoreNS && (sourceAttr.Value != targetAttr.Value))
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        if (sourceAttr.LocalName != targetAttr.LocalName)
                        {
                            return(false);
                        }
                        if (sourceAttr.Value != targetAttr.Value)
                        {
                            if (ParseAttributeValuesAsQName)
                            {
                                if (sourceAttr.ValueAsQName != null)
                                {
                                    if (!sourceAttr.ValueAsQName.Equals(targetAttr.ValueAsQName))
                                    {
                                        return(false);
                                    }
                                }
                                else
                                {
                                    if (targetAttr.ValueAsQName != null)
                                    {
                                        return(false);
                                    }
                                }
                            }
                            else
                            {
                                return(false);
                            }
                        }
                    }
                    sourceAttr = (XmlDiffAttribute)(sourceAttr.NextSibling);
                    targetAttr = (XmlDiffAttribute)(targetAttr.NextSibling);
                }
            }
            else
            {
                Hashtable sourceAttributeMap = new Hashtable();
                Hashtable targetAttributeMap = new Hashtable();

                while (sourceAttr != null && targetAttr != null)
                {
                    if (IgnorePrefix && sourceAttr.NamespaceURI == xmlnsNamespace)
                    {
                        // do nothing
                    }
                    else
                    {
                        string localNameAndNamespace = sourceAttr.LocalName + "<&&>" + sourceAttr.NamespaceURI;
                        sourceAttributeMap.Add(localNameAndNamespace, sourceAttr);
                    }
                    if (IgnorePrefix && targetAttr.NamespaceURI == xmlnsNamespace)
                    {
                        // do nothing
                    }
                    else
                    {
                        string localNameAndNamespace = targetAttr.LocalName + "<&&>" + targetAttr.NamespaceURI;
                        targetAttributeMap.Add(localNameAndNamespace, targetAttr);
                    }

                    sourceAttr = (XmlDiffAttribute)(sourceAttr.NextSibling);
                    targetAttr = (XmlDiffAttribute)(targetAttr.NextSibling);
                }

                if (sourceAttributeMap.Count != targetAttributeMap.Count)
                {
                    return(false);
                }

                foreach (string sourceKey in sourceAttributeMap.Keys)
                {
                    if (!targetAttributeMap.ContainsKey(sourceKey))
                    {
                        return(false);
                    }
                    sourceAttr = (XmlDiffAttribute)sourceAttributeMap[sourceKey];
                    targetAttr = (XmlDiffAttribute)targetAttributeMap[sourceKey];

                    if (!IgnorePrefix)
                    {
                        if (sourceAttr.Prefix != targetAttr.Prefix)
                        {
                            return(false);
                        }
                    }

                    if (sourceAttr.Value != targetAttr.Value)
                    {
                        if (ParseAttributeValuesAsQName)
                        {
                            if (sourceAttr.ValueAsQName != null)
                            {
                                if (!sourceAttr.ValueAsQName.Equals(targetAttr.ValueAsQName))
                                {
                                    return(false);
                                }
                            }
                            else
                            {
                                if (targetAttr.ValueAsQName != null)
                                {
                                    return(false);
                                }
                            }
                        }
                        else
                        {
                            return(false);
                        }
                    }
                }
            }
            return(true);
        }