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

  • SEARCH
  • Home
  • 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 7979001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:38:54+00:00 2026-06-04T09:38:54+00:00

I have an application that compared an xml file to a text file, and

  • 0

I have an application that compared an xml file to a text file, and if the contents of a specific line of the xml is the same as the text file, the program outputs a 1, but if they are different, it outputs a 0. Unfortunatley I can’t get it to output 1. It always seems to output a 0.

Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
using System.IO;



namespace CompareIt
{
    class Program
    {
        static void Main(string[] args)
        {
            using (XmlReader reader = XmlReader.Create("2.xml"))
            {
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        if (reader.Name.ToLower() == "data")
                        {
                            string xml = reader.ReadOuterXml();

                            var xmlString = (from data in XDocument.Parse(xml).Elements()
                                             select data.Elements().First().Value).FirstOrDefault();

                            xmlString = xmlString.Replace("\n", "").Trim();

                            var fileString = File.ReadAllText(@"8.txt");
                            if (xmlString == fileString)
                                Console.WriteLine("1");
                            else
                                Console.WriteLine("0");
                        }
                    }
                }
            }
        }
    }
}

The XML file (the program is supposed to only read the data section):

 <?xml version="1.0"?>
    <root>
     <Data>
      <Seperator>1</Seperator>
     </Data>
     <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
      <SignedInfo>
        <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
        <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
        <Reference URI="">
          <Transforms>
             <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
           </Transforms>
           <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
           <DigestValue>GHOSJRUqcHnZ3M090/5/KhvghyQ=</DigestValue>
         </Reference>
       </SignedInfo>
      <SignatureValue>oib+LAXqJshDFm3YM63qkSsJxxF+t0uahGax8tLrjSPJUjW045iYvB4LJCgMeF9oxatbWnVB9hGbvtVnl4iewJDL3kjnjvot5CLozMOaIGJgdys5MP8ncx771itANTm8wi8KgnqVjGjvTakEmcdwcSdRXuCP1WGOwuXm5StkY8Q=</SignatureValue>
    </Signature>
    </root>

and the text file simply contains a:

1

when I do Console.WriteLine(fileString);
or

Console.WriteLine(xmlString);

they do output the same thing though, like they are supposed to, which confuses me even more.

  • 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-04T09:38:56+00:00Added an answer on June 4, 2026 at 9:38 am

    I have tested your code and it works fine, the only reason may be that your text file contains new line after 1. You may try remove the new line just before the if statement. Use

    fileString = fileString.Replace(Environment.NewLine,"");
      if(....) //your if
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to create an application that retrieves a xml file on the web,
We have to compare responses (XML) of two different but they are doing the
I have a welcome page (JSP file) for my application that contains some dynamic
I have an application that saves its context to XML. In this application, there
I have an objective-c application for OS X that compares two sqlite DB's and
I have application that makes different queries with different results so the caching in
I have application that is connecting to the DB and if I enter incorrect
I have application that is up more than 3 days. I can see in
I have application that brings response via Ajax and creates 5-20 new jQuery click
I have two application that need to talk to each other. App1 needs to

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.