views:

255

answers:

5

I have a DataModule with XML and I need do a search...

Unfortunately there are more than 300,000 records and I can't make a loop to check one-by-one.

Is it possible to make a query without using a database?

Is there another solution?

+3  A: 

XML's fine for small amounts of information, but for a dataset that big, a relational database is really the only sane choice, especially if you need to be able to query it.

Mason Wheeler
I just read that Joel on Software post, it's pretty on topic - even if it was written in 2001.
Alister
+3  A: 

You can search using something like XPath: however, that would just mean that the XPath implementation does the searching on your behalf (which doesn't necessarily improve performance).

ChrisW
+1  A: 

There are a number of in-memory databases that may be useful. At least you could then index and query the data as required. One I know of is from components4developers.com. David

David Freeman
+2  A: 

I think it is probably important to ask Why are you using XML to store 300k records?. As XML is not the most efficient format to manipulate data with.

If you're stuck with XML then you might be best to read the XML file into some sort of database (you might get away with an in memory table, but then again you might run out of memory). I think if you use a TXMLDocument object to load the XML file into you'll either have a serious performance issue or run out of memory (I had trouble when I was playing with a 250k record xml file awhile back).

You might be able to use the MSXML DOM directly (you can probably import the type library) or use SAX which will allow you to parse it sequentially, neither of which I have had much experience with.

Alister
Yes, SAX is the way to go. It used to be available as part of MSXML. Not sure about now.
Bruce McGee
A: 

You don't say how you are implementing the datasource. I have used TClientDataSet connected via TXMLTransformProvider (OK not for 300K records) but for a few thousand. and simply setting the filter and filtered properties seems to "Query" it just fine...

Or have I missed something?

Despatcher
I read about it. You know any simple example so I can understand?
Leo
1. Plonk a TClientDataSet on the DM. Plonk a TXMLTransformProvider on DM. Set the Tranform as the provider. Start XML Mapper from the tools menu - learn how to us it :( it's not very intuitive. Once Files are Mappped via the XTR files and connected use a TDatasoure as usual. Have fun.
Despatcher