Exemplo n.º 1
0
        private bool CompareText(XPathNavigator xmlFromNav, XPathNavigator xmlToNav, out XmlDiffNode result, ref int diffNumber)
        {
            XPathNavigator xFrom = xmlFromNav.Clone();
            XPathNavigator xTo   = xmlToNav.Clone();

            result = new XmlDiffNode();

            if (xFrom.NodeType == XPathNodeType.Text && xTo.NodeType == XPathNodeType.Text)
            {
                if (!CompareTextValue(xFrom.Value, xTo.Value))
                {
                    result = new XmlDiffNode
                    {
                        XPath        = GetXPath(xFrom),
                        DiffType     = XmlDiffNode.DiffTypes.Changed,
                        Description  = "Text node does not match  |  " + xFrom.Value.Trim() + " => " + xTo.Value.Trim(),
                        DiffNodeType = XmlDiffNode.DiffNodeTypes.Text,
                        Origin       = fromFilename,
                        Comparison   = toFilename,
                        OriginLineNo = ((IXmlLineInfo)xFrom).LineNumber,
                        CompLineNo   = ((IXmlLineInfo)xTo).LineNumber,
                        DiffId       = (diffNumber++).ToString()
                    };
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 2
0
        private bool MatchElement(XPathNavigator fromNav, XPathNavigator toNav, out XmlDiffNode nodeInfo)
        {
            XPathNavigator xFrom = fromNav.Clone();
            XPathNavigator xTo   = toNav.Clone();

            nodeInfo = null;

            if (!options.IgnoreNamespace && (xFrom.NamespaceURI != xTo.NamespaceURI))
            {
                return(false);
            }
            if (!options.IgnorePrefix && (xFrom.Prefix != xTo.Prefix))
            {
                return(false);
            }
            if (xFrom.LocalName != xTo.LocalName)
            {
                return(false);
            }
            if (!options.IgnoreAttributes && !MatchAttributes(xFrom, xTo, out nodeInfo))
            {
                return(false);
            }

            if (xFrom.Value.Equals(xTo.Value))
            {
                return(true);
            }
            Debug.WriteLine(xFrom.Value);
            Debug.WriteLine(xTo.Value);
            Debug.WriteLine("*************");
            return(false);
        }
Exemplo n.º 3
0
        public string ToString(XmlDiffNode node)
        {
            StringBuilder diffLine = new StringBuilder();

            diffLine.Append("\"Edit\": ");
            switch (node.DiffType)
            {
            case XmlDiffNode.DiffTypes.Removed:
                diffLine.AppendLine("\"Delete\",");
                break;

            case XmlDiffNode.DiffTypes.Added:
                diffLine.AppendLine("\"Insert\",");
                break;

            case XmlDiffNode.DiffTypes.Changed:
                diffLine.AppendLine("\"Update\",");
                break;

            default:
                break;
            }

            diffLine.AppendLine("\"XPath\": " + "\"" + EscapeQuotes(node.XPath) + "\",");

            diffLine.AppendLine("\"Diff ID\": " + "\"" + node.DiffId + "\",");

            diffLine.AppendLine("\"Description\": " + "\"" + EscapeQuotes(node.Description) + "\",");

            diffLine.AppendLine("\"Node Type\": " + "\"" + node.DiffNodeType + "\",");

            diffLine.AppendLine("\"Origin Line No\": " + node.OriginLineNo + ",");

            diffLine.AppendLine("\"Comp Line No\": " + node.CompLineNo + ",");

            return(diffLine.ToString());
        }
Exemplo n.º 4
0
        private List <XPathNavigator> SelectSiblings(XPathNavigator fromNav, XPathNavigator toNav, out XmlDiffNode nodeInfo)
        {
            XPathNavigator        xFrom   = fromNav.Clone();
            XPathNavigator        xTo     = toNav.Clone();
            List <XPathNavigator> xToList = new List <XPathNavigator>();

            nodeInfo = null;

            xTo.MoveToFirst();
            if (xTo.NodeType != XPathNodeType.Element)
            {
                xTo.MoveToNext(XPathNodeType.Element);
            }

            do
            {
                if (MatchElement(xFrom, xTo, out nodeInfo))
                {
                    xToList.Add(xTo.Clone());
                }
            } while (xTo.MoveToNext(XPathNodeType.Element));

            return(xToList);
        }
Exemplo n.º 5
0
        private bool MatchAttributes(XPathNavigator fromNav, XPathNavigator toNav, out XmlDiffNode nodeInfo)
        {
            XPathNavigator xFrom = fromNav.Clone();
            XPathNavigator xTo   = toNav.Clone();

            nodeInfo = null;

            if (xFrom.HasAttributes)
            {
                xFrom.MoveToFirstAttribute();
                if (!options.IgnoreAttributeOrder)
                {
                    xTo.MoveToFirstAttribute();
                }

                do
                {
                    if (!options.IgnoreAttributeOrder)
                    {
                        if (!options.IgnoreNamespace && xFrom.Prefix != xTo.Prefix)
                        {
                            nodeInfo = new XmlDiffNode()
                            {
                                XPath        = null,
                                DiffType     = XmlDiffNode.DiffTypes.Changed,
                                Description  = "No matching namespace @" + xFrom.NamespaceURI,
                                DiffNodeType = XmlDiffNode.DiffNodeTypes.Text,
                                Origin       = fromFilename,
                                Comparison   = toFilename,
                                OriginLineNo = ((IXmlLineInfo)xFrom).LineNumber,
                                CompLineNo   = ((IXmlLineInfo)xTo).LineNumber,
                                DiffId       = string.Empty, // To be filled in by compare method
                            };
                            return(false);
                        }
                        if (xFrom.LocalName != xTo.LocalName || xFrom.Value != xTo.Value)
                        {
                            nodeInfo = new XmlDiffNode()
                            {
                                XPath        = null,
                                DiffType     = XmlDiffNode.DiffTypes.Changed,
                                Description  = "No matching attribute @" + xFrom.LocalName + " = " + xFrom.Value,
                                DiffNodeType = XmlDiffNode.DiffNodeTypes.Text,
                                Origin       = fromFilename,
                                Comparison   = toFilename,
                                OriginLineNo = ((IXmlLineInfo)xFrom).LineNumber,
                                CompLineNo   = ((IXmlLineInfo)xTo).LineNumber,
                                DiffId       = string.Empty, // To be filled in by compare method
                            };
                            return(false);
                        }

                        xTo.MoveToNextAttribute();
                    }
                    else
                    {
                        if (xTo.GetAttribute(xFrom.LocalName, (!options.IgnoreNamespace) ? xFrom.NamespaceURI : "") != xFrom.Value)
                        {
                            nodeInfo = new XmlDiffNode()
                            {
                                XPath        = null,
                                DiffType     = XmlDiffNode.DiffTypes.Changed,
                                Description  = "No matching attribute @" + xFrom.LocalName + " = " + xFrom.Value,
                                DiffNodeType = XmlDiffNode.DiffNodeTypes.Text,
                                Origin       = fromFilename,
                                Comparison   = toFilename,
                                OriginLineNo = ((IXmlLineInfo)xFrom).LineNumber,
                                CompLineNo   = ((IXmlLineInfo)xTo).LineNumber,
                                DiffId       = string.Empty, // To be filled in by compare method
                            };
                            return(false);
                        }
                    }
                } while (xFrom.MoveToNextAttribute());
            }

            return(true);
        }