“If” and “else” C# not outputting correctly

MoeB

New Member
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:\[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(); // Your other operations var fileString = File.ReadAllText(@"8.txt"); if (xmlString == fileString) Console.WriteLine("1"); else Console.WriteLine("0"); } } } } } }}\[/code\]The XML file (the program is supposed to only read the data section):\[code\] <?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>\[/code\]and the text file simply contains a:\[code\]1\[/code\]when I do \[code\]Console.WriteLine(fileString);\[/code\]or \[code\]Console.WriteLine(xmlString);\[/code\]they do output the same thing though, like they are supposed to, which confuses me even more.
 
Back
Top