Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing Data as XML

Tags:

database

xml

In which cases storing data as XML is preferable to RDBMS and why?

Can you give any analogy?

like image 817
user366312 Avatar asked Dec 23 '22 09:12

user366312


1 Answers

Summary

If you don't have much data and you're in total control of it (no dependent 3rd parties), XML is a nice option. Otherwise, RDBMS - see below for more reasons.

Analogy

If RDBMS is a filing cabinet (drawers of same-sized records organized by some index) then XML is a back-pack (not-necessarily-organized bag of randomly-sized records, may stick out at the corners).

Reasons for XML

1) Flexibility

If your schema is either very loose or changes over time, XML is preferable as versioning RDMS is hard once there's data inside it. In my experience, XML Serialization, XSLT and XPath queries are resilient to changes in the XML schema and can continue to work for old/new clients. For example, you can add some new elements into a document and an older EXE that reads that document will just ignore those elements. An RDBMS query that does 'SELECT * FROM table' where you just added a column will have undefined results.

2) Deployment

Easy - just ship your EXE.

3) Debugability

Easy to 'debug' the data - the XML could be human-readable already; if not, XSLT may make it more readable.

4) Interoperability

You can hand the XML off to other systems and not care what platform/technology they use.

Reasons for RDBMS

1) Performance

If you have a lot of data, then the indexing features of a RDBMS will give you best performance. Reading a large XML (> 1000 records) is expensive if you're fundamentally just trying to find the record with ID=123, which RDBMS can do in a snap. Stored Procedures would make this even better.

2) Security

You can secure parts of RDBMS through permissions - e.g. grant/deny SELECT access to various users.

3) Business Tools

There are many RDBMS tools for things such as OLAP and reporting.

like image 183
JBRWilkinson Avatar answered Jan 21 '23 14:01

JBRWilkinson