Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8580491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:50:32+00:00 2026-06-11T20:50:32+00:00

I am trying to use xmldiffpatch to write to a stream. The first method

  • 0

I am trying to use xmldiffpatch to write to a stream.

The first method is to write my xml to a memory stream.
The second method loads an xml from a file and creates a stream for the patched file to be written into. The third method actually compares the two files. I’m always getting that both files are identical, even though they are not, so I know that I am missing something.

Any help is appreciated!

public MemoryStream FirstXml() 

    {
        string[] names = { "John", "Mohammed", "Marc", "Tamara", "joy" };
        MemoryStream ms = new MemoryStream();
        XmlTextWriter xtw= new XmlTextWriter(ms, Encoding.UTF8);

        xtw.WriteStartDocument();
        xtw.WriteStartElement("root");

        foreach (string s in names)
        {
        xtw.WriteStartElement(s);
        xtw.WriteEndElement();
        }
        xtw.WriteEndElement();
        xtw.WriteEndDocument();
        return ms;
    }

    public Stream SecondXml()
    {
        XmlReader finalFile =XmlReader.Create(@"c:\......\something.xml");
        MemoryStream ms = FirstXml();
        XmlReader originalFile = XmlReader.Create(ms);
        MemoryStream ms2 = new MemoryStream();
        XmlTextWriter dgw = new XmlTextWriter(ms2, Encoding.UTF8);
        GenerateDiffGram(originalFile, finalFile, dgw);
        return ms2;
    }

    public void GenerateDiffGram(XmlReader originalFile, XmlReader finalFile,
                                XmlWriter dgw)
    {
        XmlDiff xmldiff = new XmlDiff();
        bool bIdentical = xmldiff.Compare(originalFile, finalFile, dgw);
        dgw.Close();
        StreamReader sr = new StreamReader(SecondXml());
        string xmlOutput = sr.ReadToEnd();
        if(xmlOutput.Contains("</xd:xmldiff>"))
        {Console.WriteLine("Xml files are not identical");
            Console.Read();}

        else
        {Console.WriteLine("Xml files are identical");Console.Read();}

    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T20:50:34+00:00Added an answer on June 11, 2026 at 8:50 pm

    The following modified version works.

    static void Main()
    {
        SecondXml();
    }
    
    public static string FirstXml()
    {
        string[] names = { "John", "Mohammed", "Marc", "Tamara", "joy" };
        var sw = new StringWriter();
        var xtw = new XmlTextWriter(sw);
    
        xtw.WriteStartDocument();
        xtw.WriteStartElement("root");
    
        foreach (string s in names)
        {
            xtw.WriteStartElement(s);
            xtw.WriteEndElement();
        }
        xtw.WriteEndElement();
        xtw.WriteEndDocument();
    
        return sw.ToString();
    }
    
    public static void SecondXml()
    {
        string secondXml = File.ReadAllText(@"t:\something.xml");
        string firstXml = FirstXml();
    
        Console.WriteLine("Comparing...");
    
        string result = GenerateDiffGram(firstXml, secondXml);
    
        Console.WriteLine(result);
    
        Console.WriteLine();
        Console.WriteLine("Finished compare");
    
    
        Console.Out.Write(firstXml);
    
        Console.WriteLine();
    
        Console.WriteLine();
    
        Console.WriteLine(secondXml);
    }
    
    public static string GenerateDiffGram(string originalFile, string finalFile)
    {
        var xmldiff = new XmlDiff();
        var r1 = XmlReader.Create(new StringReader(originalFile));
        var r2 = XmlReader.Create(new StringReader(finalFile));
        var sw = new StringWriter();
        var xw = new XmlTextWriter(sw) {Formatting = Formatting.Indented};
        bool bIdentical = xmldiff.Compare(r1, r2, xw);
        Console.WriteLine();
        Console.WriteLine("bIdentical: " + bIdentical);
    
        return sw.ToString();
    }
    

    I’m actually not entirely sure what’s wrong with your original code. The XML being compared is an empty string in both the first and second readers. Since you’re using memory streams as the backing stores anyways, then you won’t lose anything by just using strings as the above does.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The
I'm trying use this code to get image resolution from file bool GetImageSizeEx(const char
Trying to use Powershell to script the removal of specific custom errors from an
Trying to use this sql statement. The first 2 parts work fine, I am
I am trying use std::copy to copy from two different iterator. But during course
I'm trying use to selenium with firefox on CentOS from command line like this:
I'm trying use the Sum method in a lambda expression for a comparison, but
i'm trying use webview to load a image from sdcard i use this path
I am trying use a from a multi-dimensional array that I create in another
I'm trying to read a XML file, but I want to know just the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.