- Read in xml
- Add/alter info
- Before committing lock file
- try to write file catch exception
- Realease lock
Problems in xml when multiple users write to it at the same time using a .m script
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi,
I have been working on a script which tries to write to an xml placed in a remote machine. The application is such that some information is collected at run time by this .m script and then the information is appended as a new node to the xml placed at some remote machine. It is possible that many users run the script at the same instance.
Here is the structure of my xml:
<Usr1>
<a> Some data </a>
* Some data *
<c> Some data </c>
</Usr1>
<Usr2>
<a> Some data </a>
* Some data *
<c> Some data </c>
<d> Some data </d>
<e> Some data </e>
</Usr2>
<Usr1>
<a> Some data </a>
* Some data *
<e> Some data </e>
<f> Some data </f>
</Usr1>
The problem is that when multiple users try to write to the xml using this .m script at the same time, then all the previous data in the xml gets flushed out and the xml becomes empty. It throws the following error to one of the users trying to write:
[Fatal Error] Info.xml:998:19: XML document structures must start and end within the same entity.
The next time a user runs the .m script, he is writing to an empty xml.
In order to solve my problem i tried using the 'fileattrib' command where by when a user has started to write to an xml, then the 'Group' and the 'Other' write access should be disabled and only the 'User' access should be enabled. This way there would be a loss of only one users data at the time of 2 simultaneous writes.
But the problem is that i am working on a machine which run Windows7 OS, and we can use the 'fileattrib' cmd for enabling/disabling only the 'User' write permissions and not the other permissions.
It would be great if i could get some help.
Thanks in advance.
0 comentarios
Respuestas (1)
Oleg Komarov
el 2 de Sept. de 2011
You should lock your file before writing:
or use java: http://stackoverflow.com/questions/128038/how-can-i-lock-a-file-using-java-if-possible/128123#128123
So in general the flowchart should be:
1 comentario
Walter Roberson
el 2 de Sept. de 2011
Note: Standard locking might be effectively impossible (or at least unreliable), especially if the connection to the remote file system is through NFS. You might need a server lock-mediation program (one that should of course take in to account network congestion and BSOD's)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!