Is it “bad” to store XML in a database?

后端 未结 7 1450
感动是毒
感动是毒 2021-02-02 11:06

I have heard from several sources that storing XML in a database is \"bad\", but I have never seen/heard an actual explanation of why that is. Is it true? If it is true, can y

7条回答
  •  再見小時候
    2021-02-02 11:51

    XML is itself a kind storage format. It is most practically used for transportation of data, because it provides a common mechanic for structuring data. There are fixed rules for reading and writing XML that allow XML data to be read by anyone. Also validations and transformation to other output formats are relatively easy (using xslt). XML, however, is not the best way to store data in. It is time consuming to read XML files and they take up relatively much space. It is best to store your data in a structured manner in your database, and export the data from certain queries to XML if you need them in reports, on a website or to pass them to other parties.

    There are XML databases, but they also don't store there data in XML. They merely provide a way to save and load hierarchical data (XML is an hierarchical structure), instead of the standard table structure.

    So it is right to say that storing XML content in a blob in a database is generally not the right way to go, but there are always exceptions ofcourse.

    XML is -in contrast with what others say here- not a way to display data. It is a way to export (and import) data. It is a logical choice for transportation of data. That is because you are totally flexible in the way that you want it to export, it can easily be transformed to other formats. Like, if you have a webshop, and you want to export prices and productinformation to other parties, you could choose XML. These other parties can write easy rules to transform this data to their needs. Neither party has to know the way there prices are stored on the other side, and neither party has to write a complex tool to parse some hard to read binary that someone else has made up.

提交回复
热议问题