By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,980 Members | 877 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,980 IT Pros & Developers. It's quick & easy.

How do I read and update an xmlfile without loading and saving?

P: n/a
Hi, I'll try to explain. I'm now using C# and I have an xmlfile that
contains users and information about them, this xmlfile can be read and
changed from many threads in my application, as many users can be connected
at the same time, the user information in the file can also be changed by
other programs, like an administration application. So my xmlfile needs to
be updated as soon as any application changes a value and it needs to
reflect in every other application at once, or at least as soon as a node
being read that has been changed.

I feel that I might not be explaining very good, I'll tell how it worked for
me in Delphi:

In Delphi there were a convenient wizard that mapped my xmlfile to objects,
so I easily could just access the xmldata by accessing the properties of my
generated class, if I change a value in a property of my class it was
instantly written to the xmlfile so that other applications could notice the
changes. And if I changed a value in the xmlfile and then read the value of
the property corresponding to the node I got the new value from the file.
Exactly what I needed.

In .NET and C# however I haven't been able to find something similar?

(Accessing the xmlfile by the serializing and data classes all seams to
require me to completely load and save the whole xmlfile each time a value
changes. I also haven't find any way to know if the data in the underlying
xmlfile has changed.)

(I haven't tried much yet thou, I've been reading up on the different xml
classes in MSDN and come to this conclusion without finding a solution).

Regards,
Lani
Nov 11 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Niklas Lagergren wrote:
In Delphi there were a convenient wizard that mapped my xmlfile to objects,
so I easily could just access the xmldata by accessing the properties of my
generated class, if I change a value in a property of my class it was
instantly written to the xmlfile so that other applications could notice the
changes. And if I changed a value in the xmlfile and then read the value of
the property corresponding to the node I got the new value from the file.
Exactly what I needed.

In .NET and C# however I haven't been able to find something similar?
Sure. Just have an object of a class, which maps to your xml (you can even
generate it from XML Schema using xsd.exe). Update object's properties and
serialize object to file. What you won't get is automatic serialization when a
property changes, but this can be implemented in a couple of minutes.
(Accessing the xmlfile by the serializing and data classes all seams to
require me to completely load and save the whole xmlfile each time a value
changes. What do you mean "accessing by the serializing"? Serialize() method serialize
object to a file, no need to read or parse existing file.
I also haven't find any way to know if the data in the underlying
xmlfile has changed.)

How do you do it in Delphi? Any magic tricks? Watch file's last-modified
attribute, this is the only way I'm aware of, this can be done a very elegant
and efficient way using FileSystemWatcher class - register a watcher and be
notified whenever something is changed in a file or directory.
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.