简体   繁体   中英

What is the advantage of using XML with regards to SQL?

I've seen a few relational databases where the XML directly mirrors the SQL, and I was wondering if anyone could give me some insight as to why people use XML over other options. I was under the impression that it was more a personal preference, but I was told by a classmate that XML is considered "better" ie more efficient in certain cases. So I wanted to pose the question to you folks, because frankly I wanted a second opinion.

The question: When would you use XML instead of ColdFusion or PHP (or other alternatives)? What are some inherent advantages that would make it a more desirable option?

For example, this is what the XML might look like:

<data>
<dataObject name="Test">
    <primaryKey>Num</primaryKey>
    <foreignKey dataObject="Test" key="Num"/>
    <datums>
        <datum type="integer" key="itemRecnum" label="Item Recnum" data="required"/>
        <datum type="string" key="status" label="Status" data="required"/>
        <datum type="integer" key="idnumber" label="ID Number" data="required"/>
    </datums>
    <constraints/>
</dataObject>
</data>

So in the SQL server, each of these have a 1-1 correspondence, with each datum type being a column.

Can someone please explain what the advantages of using XML to pull from the database are? What exactly is happening here and why is it used over CF or PHP? And how is it pushing and pulling from the database?

What if you were to mix the two? Perhaps one would use coldfusion for inserts, and xml just for views?

XML is a data storage mechanism. ColdFusion and PHP are data processing languages. XML does not pull data from a database. There are lots of reasons why people store data in XML. Some of the reasons are discussed here: Why would I ever choose to store and manipulate XML in a relational database?

PHP and XML works with XML and so does ColdFusion. If you are looking to turn XML to something for an end user, you may want to consider XSLT .

The intent of XML is to store data in a flat file, humanly readable (XML has a huge overhead in the textual naming of the entities. Also it is not meant to be human readable, it is a transport medium), easily accessible form. Methods for accessing an XML data "store" are quite robust and evolving all the time, to include a proposal from Microsoft for "XQL" - an SQL equivalent designed to manipulate XML data stores. XML is so simple that it can itself be used as a database – a very flexible one, indeed: your XML implementation can be infinitely customized through tags and a different array of libraries. As a plus, should your database get corrupted, you can open it in virtually any text editor – it's a text file, after all. However, XML has a major drawback: it is slower than SQL when processing data, and requires more resources to run.

About ColdFusion & XML you can read HERE

Where XML wins is if you've got data about a business object (let's say a hotel) scattered across 20 tables and you want to send that data to someone who organizes the data quite differently into 16 tables with a different structure. XML allows you to capture all the information about the object in one message, that's independent of the design of your database and possibly conforms to some industry standard like OTA, and load it into a different database with a quite different design.

If your XML, on the other hand, is intimately tied to the tables and columns of your SQL database design, then you aren't getting much value from it.

IA/B tested a very busy site using a cached XML product file vs caching a very large query vs caching smaller individual queries and so far the XML has performed the worst everytime. The time it took to read the file find specific records and then parse the data out was crippling the server. If you have a database at hand and are looking to build a website that is data intensive I would strongly advise avoiding XML unless you are storing XML in your database for one purpose or another.

If you are really looking for a flat file system for a website I would look into NoSQL databases such as MongoDB or CouchDB there are a few Coldfusion drivers and CFC's that have been written to work with these systems.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM