當前位置: 首頁>>代碼示例>>C#>>正文


C# XmlDiffPatch.XmlDiff類代碼示例

本文整理匯總了C#中Microsoft.XmlDiffPatch.XmlDiff的典型用法代碼示例。如果您正苦於以下問題:C# XmlDiff類的具體用法?C# XmlDiff怎麽用?C# XmlDiff使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


XmlDiff類屬於Microsoft.XmlDiffPatch命名空間,在下文中一共展示了XmlDiff類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: MinimalTreeDistanceAlgo

        // Constructor
        internal MinimalTreeDistanceAlgo( XmlDiff xmlDiff )
        {
            Debug.Assert( OperationCost.Length - 1 == (int)XmlDiffOperation.Undefined,
                      "Correct the OperationCost array so that it reflects the XmlDiffOperation enum." );

            Debug.Assert( xmlDiff != null );
            _xmlDiff = xmlDiff;
        }
開發者ID:Podracer,項目名稱:DAE-notepad,代碼行數:9,代碼來源:TreeMappingAlgorithm.cs

示例2: TestSerialization

        public void TestSerialization()
        {
            MSBuildCodeMetricsReport report = MSBuildCodeMetricsReport.Create().CreateSummary().Report.CreateDetails().Report;

            report.Summary.AddMetric("VisualStudioMetrics", _cyclomaticComplexity).CreateRanges().
                AddRange("> 10", 5).
                AddRange("<= 10 and > 5", 3).
                AddRange("<= 5", 1);

            report.Summary.AddMetric("VisualStudioMetrics", _linesOfCode).CreateRanges().
                AddRange("> 100", 5).
                AddRange("<= 100 and > 50", 3).
                AddRange("<= 50", 1);

            report.Details.AddMetric("VisualStudioMetrics", _cyclomaticComplexity).CreateMeasures().
                AddMeasure("Method1() : void", 100).
                AddMeasure("Method2() : void", 50);

            report.Details.AddMetric("VisualStudioMetrics", _linesOfCode).CreateMeasures().
                AddMeasure("Method1() : void", 1000).
                AddMeasure("Method2() : void", 500);

            Stream ms = report.SerializeToMemoryStream(true);
            XmlDiff diff = new XmlDiff();
            Assert.IsTrue(diff.Compare(_expectedReportStream, ms));
        }
開發者ID:ericlemes,項目名稱:MSBuildCodeMetrics,代碼行數:26,代碼來源:SerializationTests.cs

示例3: Comparer

 public Comparer(IDiffManager manager)
 {
     _results = new List<BaseDiffResultObject>();
     _diff = new XmlDiff();
     _diffOptions = new XmlDiffOptions();
     _tempFilePath = Path.GetTempFileName();
     Manager = manager;
 }
開發者ID:silvestrova,項目名稱:Custom-XML-Diff,代碼行數:8,代碼來源:Comparer.cs

示例4: Equal

        internal static void Equal(string file1, string file2)
        {
            var diffFile = @"diff.xml";
            XmlTextWriter tw = new XmlTextWriter(new StreamWriter(diffFile));
            tw.Formatting = Formatting.Indented;
            var diff = new XmlDiff();
            diff.Options = XmlDiffOptions.IgnoreWhitespace | XmlDiffOptions.IgnoreComments | XmlDiffOptions.IgnoreXmlDecl;
            var result = diff.Compare(file1, file2, false, tw);
            tw.Close();
            if (!result)
            {
                //Files were not equal, so construct XmlDiffView.
                XmlDiffView dv = new XmlDiffView();

                //Load the original file again and the diff file.
                XmlTextReader orig = new XmlTextReader(file1);
                XmlTextReader diffGram = new XmlTextReader(diffFile);
                dv.Load(orig, diffGram);
                string tempFile = "test.htm";

                StreamWriter sw1 = new StreamWriter(tempFile);
                //Wrapping
                sw1.Write("<html><body><table>");
                sw1.Write("<tr><td><b>");
                sw1.Write(file1);
                sw1.Write("</b></td><td><b>");
                sw1.Write(file2);
                sw1.Write("</b></td></tr>");

                //This gets the differences but just has the 
                //rows and columns of an HTML table
                dv.GetHtml(sw1);

                //Finish wrapping up the generated HTML and 
                //complete the file by putting legend in the end just like the 
                //online tool.

                sw1.Write("<tr><td><b>Legend:</b> <font style='background-color: yellow'" +
                " color='black'>added</font>&nbsp;&nbsp;<font style='background-color: red'" +
                "color='black'>removed</font>&nbsp;&nbsp;<font style='background-color: " +
                "lightgreen' color='black'>changed</font>&nbsp;&nbsp;" +
                "<font style='background-color: red' color='blue'>moved from</font>" +
                "&nbsp;&nbsp;<font style='background-color: yellow' color='blue'>moved to" +
                "</font>&nbsp;&nbsp;<font style='background-color: white' color='#AAAAAA'>" + "ignored</font></td></tr>");

                sw1.Write("</table></body></html>");

                //HouseKeeping...close everything we dont want to lock.
                sw1.Close();
                orig.Close();
                diffGram.Close();
                Process.Start("test.htm");
            }

            Assert.True(result);
        }
開發者ID:jexuswebserver,項目名稱:Microsoft.Web.Administration,代碼行數:56,代碼來源:XmlAssert.cs

示例5: DefaultDiffEngine

        /// <summary>
        /// Create a default XML difference engine using the <see cref="DefaultDiffOptions" />
        /// </summary>
        /// <returns></returns>
        public static XmlDiff DefaultDiffEngine()
        {
            var xmlDiff = new XmlDiff
            {
                Options = DefaultDiffOptions(),
                Algorithm = XmlDiffAlgorithm.Auto
            };

            return xmlDiff;
        }
開發者ID:RustyF,項目名稱:EnergyTrading-Core,代碼行數:14,代碼來源:XmlDiffFactory.cs

示例6: CoordinateSystemXmlReaderTest

		public CoordinateSystemXmlReaderTest() 
		{
			XmlDiffOptions ignoreMost = XmlDiffOptions.IgnoreChildOrder | 
				XmlDiffOptions.IgnoreComments | 
				XmlDiffOptions.IgnoreDtd | 
				XmlDiffOptions.IgnorePI |
				XmlDiffOptions.IgnoreWhitespace |
				XmlDiffOptions.IgnoreXmlDecl ;

			_xmlDiff = new XmlDiff(ignoreMost);
		}
開發者ID:xuchuansheng,項目名稱:GenXSource,代碼行數:11,代碼來源:CoordinateSystemXmlReaderTest.cs

示例7: XmlHash

// Constructor

	internal XmlHash( XmlDiff xmlDiff )
	{
        // set flags
        _bIgnoreChildOrder  = xmlDiff.IgnoreChildOrder;
        _bIgnoreComments    = xmlDiff.IgnoreComments;
        _bIgnorePI          = xmlDiff.IgnorePI;
        _bIgnoreWhitespace  = xmlDiff.IgnoreWhitespace;
        _bIgnoreNamespaces  = xmlDiff.IgnoreNamespaces;
        _bIgnorePrefixes    = xmlDiff.IgnorePrefixes;
        _bIgnoreXmlDecl     = xmlDiff.IgnoreXmlDecl;
        _bIgnoreDtd         = xmlDiff.IgnoreDtd;
	}
開發者ID:ViniciusConsultor,項目名稱:sqlschematool,代碼行數:14,代碼來源:XmlHash.cs

示例8: GenerateDiffGram

        public XElement GenerateDiffGram(XElement element1, XElement element2) {
            using (var node1Reader = element1.CreateReader())
            using (var node2Reader = element2.CreateReader()) {
                var result = new XDocument();
                using (var writer = result.CreateWriter()) {
                    var diff = new XmlDiff(XmlDiffOptions.IgnoreChildOrder | XmlDiffOptions.IgnoreWhitespace | XmlDiffOptions.IgnoreComments | XmlDiffOptions.IgnoreXmlDecl);
                    diff.Compare(node1Reader, node2Reader, writer);
                    writer.Flush();
                    writer.Close();
                }

                return result.Root;
            }
        }
開發者ID:Higea,項目名稱:Orchard,代碼行數:14,代碼來源:DiffGramAnalyzer.cs

示例9: DiffXmlStrict

        public static void DiffXmlStrict(string actual, string expected)
        {
            XmlDocument expectedDoc;
            XmlDocument actualDoc;

            try
            {
                expectedDoc = new XmlDocument();
                expectedDoc.LoadXml(expected);
            }
            catch (XmlException e)
            {
                throw new Exception("Expected: " + e.Message + "\r\n" + expected);
            }

            try
            {
                actualDoc = new XmlDocument();
                actualDoc.LoadXml(actual);
            }
            catch (XmlException e)
            {
                throw new Exception("Actual: " + e.Message + "\r\n" + actual);
            }

            using (var stringWriter = new StringWriter())
            using (var writer = new XmlTextWriter(stringWriter))
            {
                writer.Formatting = Formatting.Indented;

                var xmldiff = new XmlDiff(XmlDiffOptions.None
                    //XmlDiffOptions.IgnoreChildOrder |
                    | XmlDiffOptions.IgnoreNamespaces
                    //XmlDiffOptions.IgnorePrefixes
                    );
                var identical = xmldiff.Compare(expectedDoc, actualDoc, writer);

                if (!identical)
                {
                    var error = string.Format("Expected:\r\n{0}\r\n\r\n" + "Actual:\r\n{1}\r\n\r\nDiff:\r\n{2}",
                        expected, actual, stringWriter.GetStringBuilder());

                    throw new Exception(error);
                }
            }
        }
開發者ID:razer21,項目名稱:WebApiProblem,代碼行數:46,代碼來源:XmlDiff.cs

示例10: CompareXML

        internal static bool CompareXML(XDocument xmlDocument1, XDocument xmlDocument2)
        {
            XmlDiff diff = new XmlDiff();
            diff.IgnoreChildOrder = true;
            diff.IgnoreXmlDecl = true;
            diff.IgnoreWhitespace = true;
            diff.IgnoreComments = true;
            diff.IgnorePI = true;
            diff.IgnoreDtd = true;
            var doc1 = new XmlDocument();
            doc1.LoadXml(xmlDocument1.ToString());
            var doc2 = new XmlDocument();
            doc2.LoadXml(xmlDocument2.ToString());

            bool result = diff.Compare(doc1, doc2);

            return result;
        }
開發者ID:dur41d,項目名稱:sdmxdotnet,代碼行數:18,代碼來源:Utility.cs

示例11: CompareJson

 public static bool CompareJson(string expected, string actual)
 {
     var expectedDoc = JsonConvert.DeserializeXmlNode(expected, "root");
     var actualDoc = JsonConvert.DeserializeXmlNode(actual, "root");
     var diff = new XmlDiff(XmlDiffOptions.IgnoreWhitespace |
                            XmlDiffOptions.IgnoreChildOrder);
     using (var ms = new MemoryStream())
     {
         var writer = new XmlTextWriter(ms, Encoding.UTF8);
         var result = diff.Compare(expectedDoc, actualDoc, writer);
         if (!result)
         {
             ms.Seek(0, SeekOrigin.Begin);
             Console.WriteLine(new StreamReader(ms).ReadToEnd());
         }
         return result;
     }
 }
開發者ID:boghbogh,項目名稱:sandbox,代碼行數:18,代碼來源:CRUDTests.cs

示例12: Serializable

        public void Serializable()
        {
            XmlDiff diff = new XmlDiff();
            LayoutBox layoutBox = LayoutBox.LoadFromString(LayoutingResource.LayoutsDefault);
            String result = layoutBox.Serialize();

            diff.IgnoreChildOrder = true;
            diff.IgnoreComments = true;
            diff.IgnoreDtd = true;
            diff.IgnoreNamespaces = true;
            diff.IgnorePI = true;
            diff.IgnorePrefixes = true;
            diff.IgnoreWhitespace = true;
            diff.IgnoreXmlDecl = true;

            StringWriter diffgramString = new StringWriter();
            XmlTextWriter diffgramXml = new XmlTextWriter(diffgramString);
            bool diffBool = diff.Compare(new XmlTextReader(new StringReader(result)), new XmlTextReader(new StringReader(LayoutingResource.LayoutsDefault)), diffgramXml);
            //MessageBox.Show(diffgramString.ToString());
            Assert.True(diffBool);
        }
開發者ID:jonbws,項目名稱:strengthreport,代碼行數:21,代碼來源:LayoutBoxTest.cs

示例13: Compare

        /// <summary>
        /// Compares the two XML files and throws an error if they are different.
        /// </summary>
        public static void Compare(XmlDocument expected, XmlDocument actual)
        {
            XmlNamespaceManager ns = new XmlNamespaceManager(expected.NameTable);
            ns.AddNamespace("tst", "http://schemas.asidua.com/testing");

            var diffReport = new StringBuilder();

            //  Remove the ignored nodes from both XML documents
            foreach (XmlAttribute ignored in expected.SelectNodes("//@tst:IGNORE[.='Content']", ns))
            {
                string xpath = generateXPath(ignored.OwnerElement);

                //  Remove the node's content from the expected results
                ignored.OwnerElement.InnerText = "";
                ignored.OwnerElement.RemoveAttribute(ignored.Name);

                //  Remove the node's content from the actual results
                var node = actual.SelectSingleNode(xpath);
                if (node != null) node.InnerText = "";
            }

            XmlDiff comparer = new XmlDiff();
            comparer.Options = XmlDiffOptions.IgnoreComments | XmlDiffOptions.IgnoreNamespaces | XmlDiffOptions.IgnorePrefixes | XmlDiffOptions.IgnoreWhitespace | XmlDiffOptions.IgnoreXmlDecl;

            var settings = new XmlWriterSettings
            {
                OmitXmlDeclaration = true,
                Indent = true,
            };
            using (var writer = XmlWriter.Create(diffReport, settings))
            {
                Assert.IsTrue(
                    comparer.Compare(expected, actual, writer),
                    "Expected Results:\n{0}\n\n" +
                    "Actual Results:\n{1}\n\n" +
                    "Difference Report:\n{2}",
                    formatXml(expected), formatXml(actual), diffReport
                );
            }
        }
開發者ID:AlanGibson-Asidua,項目名稱:hello-adi-fuseesb,代碼行數:43,代碼來源:Utilities.cs

示例14: DoCompare

        private void DoCompare(string changed)
        {
            CleanupTempFiles();

            XmlDocument original = this.model.Document;
            XmlDocument doc = new XmlDocument();

            XmlReaderSettings settings = model.GetReaderSettings();
            using (XmlReader reader = XmlReader.Create(changed, settings)) {
                doc.Load(reader);
            }

            string startupPath = Application.StartupPath;
            //output diff file.
            string diffFile = Path.Combine(Path.GetTempPath(),
                Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + ".xml");
            this.tempFiles.AddFile(diffFile, false);

            bool isEqual = false;
            XmlTextWriter diffWriter = new XmlTextWriter(diffFile, Encoding.UTF8);
            diffWriter.Formatting = Formatting.Indented;
            using (diffWriter) {
                XmlDiff diff = new XmlDiff();
                isEqual = diff.Compare(original, doc, diffWriter);
                diff.Options = XmlDiffOptions.None;
            }

            if (isEqual) {
                //This means the files were identical for given options.
                MessageBox.Show(this, SR.FilesAreIdenticalPrompt, SR.FilesAreIdenticalCaption,
                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            string tempFile = Path.Combine(Path.GetTempPath(),
                Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + ".htm");
            tempFiles.AddFile(tempFile, false);

            using (XmlReader diffGram = XmlReader.Create(diffFile, settings)) {
                XmlDiffView diffView = new XmlDiffView();
                diffView.Load(new XmlNodeReader(original), diffGram);
                using (TextWriter htmlWriter = new StreamWriter(tempFile)) {
                    SideBySideXmlNotepadHeader(this.model.FileName, changed, htmlWriter);
                    diffView.GetHtml(htmlWriter);
                }
            }

            /*
            Uri uri = new Uri(tempFile);
            WebBrowserForm browserForm = new WebBrowserForm(uri, "XmlDiff");
            browserForm.Show();
            */
        }
開發者ID:ic014308,項目名稱:xml-notepad-for-mono,代碼行數:53,代碼來源:FormMain.cs

示例15: WriteTo

        // Methods
        internal override void WriteTo( XmlWriter xmlWriter, XmlDiff xmlDiff )
        {
            xmlWriter.WriteStartElement( XmlDiff.Prefix, "node", XmlDiff.NamespaceUri );
            xmlWriter.WriteAttributeString( "match", _sourceNode.GetRelativeAddress() );

            WriteChildrenTo( xmlWriter, xmlDiff );

            xmlWriter.WriteEndElement();
        }
開發者ID:ariflagiwale,項目名稱:PSUpdateXml,代碼行數:10,代碼來源:DiffgramOperation.cs


注:本文中的Microsoft.XmlDiffPatch.XmlDiff類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。