コード例 #1
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)
            {
                return(false);
            }

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

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

            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.LocalName != targetAttr.LocalName || sourceAttr.Value != targetAttr.Value)
                {
                    return(false);
                }
                sourceAttr = (XmlDiffAttribute)(sourceAttr.NextSibling);
                targetAttr = (XmlDiffAttribute)(targetAttr.NextSibling);
            }
            return(true);
        }
コード例 #2
0
ファイル: XmlDiff.cs プロジェクト: yunyuping0/CoreWCF
        // 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)
            {
                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);
        }
コード例 #3
0
 internal AttributeInterval(XmlDiffAttribute attr, AttributeInterval next)
 {
     this._firstAttr = attr;
     this._lastAttr  = attr;
     this._next      = next;
 }