Create and sort on XML File

P

Peter

Currently I've I'm keeping a log file, or history file of how one our app's
is used. I just have the app write data to a text file, so for each time it
is ran I'm appending a line of text that is comma separated.

The idea is that I can have another app read in that text file, and I'll be
able to sort or filter based up different data a user selects. I figure I
can write an app in C# that will parse the log file, and let a user select
the information they want to view, or take that text file, write in a XML
format, and I should have a easier time of sorting /filter on a XML file
versus a txt file

So my question is how, do I go from a text file, and create a XML file from
it?
 
P

Peter

The format of the text file I've got is as follows
// Date, Start time, Elasped Time, Part Number

05/03/2010,17:05:04,00:00:31,1234567
05/03/2010,17:06:28,00:01:00,1234567
05/04/2010,07:34:51,00:00:53,1234567
05/04/2010,07:37:46,00:21:48,1234567
05/04/2010,08:16:45,00:18:38,1234567
05/04/2010,08:31:16,00:15::42,1234567
 
M

Mr. Arnold

Peter said:
Currently I've I'm keeping a log file, or history file of how one our app's
is used. I just have the app write data to a text file, so for each time it
is ran I'm appending a line of text that is comma separated.

The idea is that I can have another app read in that text file, and I'll be
able to sort or filter based up different data a user selects. I figure I
can write an app in C# that will parse the log file, and let a user select
the information they want to view, or take that text file, write in a XML
format, and I should have a easier time of sorting /filter on a XML file
versus a txt file

So my question is how, do I go from a text file, and create a XML file from
it?


You make a accessor class/object like Person in the example that will
hold the data of the textfile and you XML serialize Person. You can use
Google to find out how to deserialize the XML back to an object read by
another program.

http://support.microsoft.com/kb/815813
 
M

Mr. Arnold

Peter said:
The format of the text file I've got is as follows
// Date, Start time, Elasped Time, Part Number

05/03/2010,17:05:04,00:00:31,1234567
05/03/2010,17:06:28,00:01:00,1234567
05/04/2010,07:34:51,00:00:53,1234567
05/04/2010,07:37:46,00:21:48,1234567
05/04/2010,08:16:45,00:18:38,1234567
05/04/2010,08:31:16,00:15::42,1234567


It's a comma delimited file. So use the Split statement and delimit the
record into variables.

You create a class call it Peter.

public class peter
{

public string TheDate {get; set;}
public string ST {get; set;}
// do ET and PN properties.

}


var peters = new List<peter>();

During the read of the text record, do the 'Split' into variables, which
would be 4 variables outputted.

var p = new peter();

p.TheDate = dt; // the variable populated by the Split

do the rest of them

peters.Add(p)


You then you Google and find out how to XML serialize a List<T> of objects
to an XML file, and deserialize the XML file of objects back to a List<T> of
objects.

It can't get any simpler than that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top