Example #1
0
        private NodePosition ComparePIs(XmlDiffProcessingInstruction pi1, XmlDiffProcessingInstruction pi2)
        {
            Debug.Assert(pi1 != null);
            Debug.Assert(pi2 != null);

            int nCompare = 0;

            if ((nCompare = CompareText(pi2.Name, pi1.Name)) == 0)
            {
                if ((nCompare = CompareText(pi2.Value, pi1.Value)) == 0)
                {
                    return(NodePosition.After);
                }
            }
            if (nCompare > 0)
            {
                //pi2 > pi1
                return(NodePosition.After);
            }
            else
            {
                //pi2 < pi1
                return(NodePosition.Before);
            }
        }
Example #2
0
        private void LoadPI(XmlDiffNode parent, XmlReader reader, PositionInfo pInfo)
        {
            XmlDiffProcessingInstruction pi = new XmlDiffProcessingInstruction(reader.Name, reader.Value);

            pi.LineNumber   = pInfo.LineNumber;
            pi.LinePosition = pInfo.LinePosition;
            InsertChild(parent, pi);
        }
Example #3
0
        // This function compares the two nodes passed to it, depending upon the options set by the user.
        private DiffType CompareNodes(XmlDiffNode sourceNode, XmlDiffNode targetNode)
        {
            if (sourceNode.NodeType != targetNode.NodeType)
            {
                return(DiffType.NodeType);
            }
            switch (sourceNode.NodeType)
            {
            case XmlDiffNodeType.Element:
                XmlDiffElement sourceElem = sourceNode as XmlDiffElement;
                XmlDiffElement targetElem = targetNode as XmlDiffElement;
                Debug.Assert(sourceElem != null);
                Debug.Assert(targetElem != null);
                if (!IgnoreNS)
                {
                    if (sourceElem.NamespaceURI != targetElem.NamespaceURI)
                    {
                        return(DiffType.NS);
                    }
                }
                if (!IgnorePrefix)
                {
                    if (sourceElem.Prefix != targetElem.Prefix)
                    {
                        return(DiffType.Prefix);
                    }
                }

                if (sourceElem.LocalName != targetElem.LocalName)
                {
                    return(DiffType.Element);
                }
                if (!IgnoreEmptyElement)
                {
                    if ((sourceElem is XmlDiffEmptyElement) != (targetElem is XmlDiffEmptyElement))
                    {
                        return(DiffType.Element);
                    }
                }
                if (!CompareAttributes(sourceElem, targetElem))
                {
                    return(DiffType.Attribute);
                }
                break;

            case XmlDiffNodeType.Text:
            case XmlDiffNodeType.Comment:
            case XmlDiffNodeType.WS:
                XmlDiffCharacterData sourceText = sourceNode as XmlDiffCharacterData;
                XmlDiffCharacterData targetText = targetNode as XmlDiffCharacterData;
                Debug.Assert(sourceText != null);
                Debug.Assert(targetText != null);

                if (ConcatenateAdjacentTextNodes)
                {
                    DoConcatenateAdjacentTextNodes(sourceText);
                    DoConcatenateAdjacentTextNodes(targetText);
                }

                if (IgnoreWhitespace)
                {
                    if (sourceText.Value.Trim() == targetText.Value.Trim())
                    {
                        return(DiffType.Success);
                    }
                }
                else
                {
                    if (sourceText.Value == targetText.Value)
                    {
                        return(DiffType.Success);
                    }
                }
                if (sourceText.NodeType == XmlDiffNodeType.Text || sourceText.NodeType == XmlDiffNodeType.WS)     //should ws nodes also as text nodes???
                {
                    return(DiffType.Text);
                }
                else if (sourceText.NodeType == XmlDiffNodeType.Comment)
                {
                    return(DiffType.Comment);
                }
                else if (sourceText.NodeType == XmlDiffNodeType.CData)
                {
                    return(DiffType.CData);
                }
                else
                {
                    return(DiffType.None);
                }

            case XmlDiffNodeType.PI:
                XmlDiffProcessingInstruction sourcePI = sourceNode as XmlDiffProcessingInstruction;
                XmlDiffProcessingInstruction targetPI = targetNode as XmlDiffProcessingInstruction;
                Debug.Assert(sourcePI != null);
                Debug.Assert(targetPI != null);
                if (sourcePI.Name != targetPI.Name || sourcePI.Value != targetPI.Value)
                {
                    return(DiffType.PI);
                }
                break;

            default:
                break;
            }

            return(DiffType.Success);
        }