tags:

views:

34

answers:

2

C#

I have a XML file that contains serealized datatable. Each row represent and event. The amount of events can reach up to milions, and loading all this data can take a very long time, and can cause the program to crash (No memory).

Is there a way to load only the last X rows of an XML file to the datatable, and then save them without overwriting the existing rows (in the XML) that does not exist in the datatable?

+2  A: 

It sounds like you should be using a database. If you're trying to manipulate a bunch of data via an XML file as the main storage method, you're going to run into a huge number of crippling problems. I suggest you change your approach to a more proven method.

JoshD
Such as? Can you tell me about more proven methods?
Gilad Naaman
A [database](http://en.wikipedia.org/wiki/Database). I'd need to know a bit more about exactly what you're doing to provide further recommendations.
JoshD
+1  A: 

XML is not well suited to such a task; it isn't very dense (but density is desirable with high volumes), expensive to process, and non-appendable.

As has already been suggested a database may be appropriate, but there are also file formats that could help here (storing the simple directly; no db abstraction). The biggest stumbling block, however, is the "last n" requirement. Unless you store that offset separately this is very tricky (assuming each record isn't fixed size).

Let me know if you want me to suggest something more specific.

Marc Gravell
Something more specific please :-)...I dont know how to use databases, i'm still learning.Is it smart to use JSON?
Gilad Naaman
@gilad I'd probably use protobuf, since it is very dense and cheap to process. Much, much faster and smaller than XML or json. And you can append trivially.
Marc Gravell
Thank you :)Can you give me links to articles about prtobuf?I'm not very good at googling.
Gilad Naaman
I found the homepage of protobuf, and found the getting started.Thank you very much :)
Gilad Naaman
@gilad for info, I'm one of the implementors (protobuf-net specifically). Let me know if you get stuck!
Marc Gravell
Yes, I do need help.I downloaded protobuff, but I don't know how to start.I guess I can't jus't write [ProtoContract] and start using it.
Gilad Naaman
@Gilad I'm tied up right now (not at PC), but you need to add [ProtoMember(n)] with unique n (usually 1,2,3) per property. The use Serializer.Serialize and it should work. There are examples here on stakoveflow or linked fro protobuf-net home page.
Marc Gravell
@Gilad also, if you describe your model (I.e. What toy want to serialize) I can so a more-specific example. Either here, or feel free to email an example class file that you need to serialize.
Marc Gravell
I need to serialize a datatable, not a class, so i guess i don't need (or can) to add a unique idntifier.Also, in what namespace Serializer.Serialize is located?
Gilad Naaman
System.ProtoBuf - and IMO DataTable is bot necessarily the best choice for a DTO
Marc Gravell