When deciding where to store your data, traditional Relational database such as Oracle, Microsoft’s SQL Server, or the ever-popular open source MySQL are most popular. Alternatively, you could choose to use XML. Though XML is not the best choice to choose as a database in your applications, it has its own merits and demerits.
What to do, if you have opted for XML as a huge relational database:
- Design the XML Schema, more robust.
- Even if the XML schema changes often, code changes should be minimal to handle the schema changes.
- If your application is unmanaged code (C++), decide on which type of parser to use. There are a lot of parsers available, including open source and third party parsers. Go for an event triggered parser. (Ex: SAX Parser)
- The type of parser determines the performance of your application.
- Handling transaction is a major part of XML as a database. You can implement your own transaction logic, but make sure to handle the transactions properly for possible memory leaks.
- If your application is managed code (C#), there are a lot of ways in loading the XML data into your application. XML Serialization will load the data faster when compared to other methods.
- Since your database is huge, load the data from the database only when it is required. For doing this, design your own server, such that it will load the needed data into the memory and if the same data is required by the application, take it from the memory/server instead of accessing the database.
When to go for XML:
- XML is viable depending on the context. If your data is pretty static, and not changing much XML will be a good use.
- Configuration settings, sample data (even if it's millions of rows, but rarely changing), are all good uses of XML.
- Easily portable and platform independent.
- Human readable format
- Open source
XML is very verbose. Data stored in an XML file will take much more disk space then the same data stored in any reasonable database system. The name of a particular field will be stored twice. For example, to store a single integer variable XML representation will be <value>24</value>.
XML does not offer role-based security like other database applications.
XML is not the best choice to use as a database for a larger database applications. XML is best suited to store configurations and for smaller database applications. In order to use it for larger applications, safety precautions to be taken care right from the design, in order to ensure performance of your application.
- “Beginning XML” by Joe Fawcett, Danny Ayers, Liam R. E. Quin