Groups | Blog | Home
all groups > dotnet xml > december 2005 >

dotnet xml : synchronization of Xml file access in .net Pro


rathoreaditya81 NO[at]SPAM gmail.com
12/1/2005 1:41:17 AM
Hi,

Iam trying to develop a solution for my comapny in MS VS Pro, using
C++.net. My work involves extensive usage of xml as well. I use DOM
model for xml opeartions.

Now the problem scenario is that multiple clients might be using my
application as same time and trying to modify/update the same xml file.
Therefore i need a mechanism to provide a synchronous access to the xml
file.

One very obvious solution to this problem is that I use lock on the
file access.
Other solution can invlove some kind of usage of synclock to lock the
block the code accessing/updating the xml file.
But i guess both the solution doesn't seems elegant enough.

I was just wondering whether is there anything provided through which i
can just lock the xml element/node being modified or updated and not
the complete file or any part of code.

Any help or suggestion regarding will be highly appreciated.

Thanking in advance,
Aditya
CJ
12/2/2005 8:37:10 AM
I just ran into this issue as well and from what i read, you will want
to use a Monitor to block access to the code that is updating the xml.
Monitor is the only lock that appeared to be feasible across multiple
processes although you may want to run logic that allows read access to
the file if you know that there isn't the need for write access for a
specific client. FileStream is good for this where you would open with
FileShare and FileAccess properties which would depend on the
functionality needed at the time.

Hope this helps a little. I personally found that this didnt seem very
scalable if you need that in your design. Another way you might go
about it is to cache the xml with a file dependency where you would
lock against writes to the file on disk but any read requests would
just hit the cache.

Regards,
-CJ
AddThis Social Bookmark Button