Groups | Blog | Home
all groups > dotnet xml > march 2004 >

dotnet xml : Few questions about efficency



Ayende Rahien
3/20/2004 6:15:06 AM
I'm trying to use xml files as my data store (after trying a DB ended
up in multiply injuries to all participants :-+AH0- ) in an Asp.Net
application.
My problem goes like this:
I'm loading the files to XmlDocument, and then grab the info I want
from them using XPath. Most of the work is reading the data.
Now, I wonder how to do this properly:
1) Should I use a single XmlDocument object, and load it whenever I get
a request? Or should I use some sort of caching?
2) How do I protect myself from multiply pages writing to the file at
the same time and corrupting it, is this even a concern if I'm not
using multi-threading?
3) I've to select nodes based on their date being in range. I can see
two ways to do it (Date format: +ACI-yyyy-MM-dd hh:mm:ss+ACI-) string
compare inside the xpath, or select all nodes and remove the ones which
are not in range in my code. Which would be better?

Thankes in advances,
Christoph Schittko [MVP]
3/21/2004 8:54:43 PM
Ayende,

I think more people will get hurt if you're trying to use an XmlDocument as
a data store for an appication with multiple concurrent users. So to answer
your question 2), yes this is very much an issue, because Asp.NET is
multi-threaded application. Requests are handled by different threads and
each request may try to read data from your document.

You may be able to get away with it if you never ever have to update the
document, but if you're reading and writing data to the document then it's
more trouble than it's worth. In the latter case you are totally on your own
to manage concurrent access to the Xml document. There is no access
synchronization capability built-into the XmlDocument class (or the
XPathNavigator).

If you are only reading data from the document, then load the data into an
XPathDocument, create an XPathNavigator and then execute the XPath queries
against the navigator.

The answer to question 3 depends on the number of nodes in your document.
The best way to the "right" answer is to try it out.

Can you elaborate why you don't want to go with a database? It's by far the
better option if you don't want to either a) want all requests trying to
read the XmlDocument to wait until one write operation is done or b0 shut
down your web site every time you need update the XmlDocument.

--
HTH
Christoph Schittko [MVP, XmlInsider]
Software Architect, .NET Mentor

[quoted text, click to view]

AddThis Social Bookmark Button