I need to create a program (preferably in C#) that reads in 2 files of different types (most likely .txt and .xls) with slightly different fields and compares each line. For example: File 1 (.txt): Last name: Smith First name: Bill EID: bs223 Type: Accounting File 2 (.xls): last: smith first: bill EID: bs223 number: 5555555 type: accounting
The files have some same fields, some different. Also, the text file will have many spaces in between fields. I need to compare common fields and display to the user the similarities and differences. The format of the fields in each file will be consistent.
My question is, what would be the best option to take in doing this? Would it be wise to convert both files to XML and compare through that? How would XML come into the equation if i used it? Are there better methods in C#?
Thanks!
EDIT: The code to convert .txt to XML
public static void Main() {
XElement root = new XElement("root");
foreach (String ln in File.ReadAllLines(@"input.txt")){
string[] fields = ln.Split(' ');
XElement record = new XElement("record");
int pos = 0;
foreach (String sp in fields){
if(sp != ""){
pos += 1;
XElement field = new XElement(string.Format("field_{0}",
pos.ToString()));
field.Add(sp);
record.Add(field);
}
}
root.Add(record);
}
Console.Write (root.ToString());
}