Example #1
0
        private static XPathExpression GenerateXPathExpression(string expression, XmlDiffAdvancedOptions advOptions, XPathNavigator nav)
        {
            XPathExpression expr = nav.Compile(expression);

            if (advOptions.HadAddedNamespace())
            {
                XmlNamespaceManager xnm = new XmlNamespaceManager(nav.NameTable);

                foreach (KeyValuePair <string, string> each in advOptions.AddedNamespaces)
                {
                    xnm.AddNamespace(each.Key, each.Value);
                }

                expr.SetContext(xnm);
            }

            return(expr);
        }
Example #2
0
        public bool Compare(XmlReader source, XmlReader target, XmlDiffAdvancedOptions advOptions)
        {
            InitFiles();

            _SourceDoc.Load(source);
            _TargetDoc.Load(target);
            XPathNavigator nav = _SourceDoc.CreateNavigator();

            if (!string.IsNullOrEmpty(advOptions.IgnoreChildOrderExpr))
            {
                XPathExpression expr = GenerateXPathExpression(
                    advOptions.IgnoreChildOrderExpr,
                    advOptions,
                    nav);

                _SourceDoc.SortChildren(expr);
                _TargetDoc.SortChildren(expr);
            }

            if (advOptions.IgnoreNodesExpr != null && advOptions.IgnoreNodesExpr != "")
            {
                XPathExpression expr = GenerateXPathExpression(
                    advOptions.IgnoreNodesExpr,
                    advOptions,
                    nav);

                _SourceDoc.IgnoreNodes(expr);
                _TargetDoc.IgnoreNodes(expr);
            }

            if (advOptions.IgnoreValuesExpr != null && advOptions.IgnoreValuesExpr != "")
            {
                XPathExpression expr = GenerateXPathExpression(
                    advOptions.IgnoreValuesExpr,
                    advOptions,
                    nav);

                _SourceDoc.IgnoreValues(expr);
                _TargetDoc.IgnoreValues(expr);
            }

            return(Diff());
        }