简体   繁体   English

就SQL而言,使用XML有什么优势?

[英]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. 我已经看到了一些关系数据库,其中XML直接反映了SQL,并且我想知道是否有人可以为我提供一些见解,说明为什么人们使用XML而不是其他选择。 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. 我的印象是,这更是个人喜好,但是一位同学告诉我,XML被认为“更好”,即在某些情况下更有效。 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)? 问题:什么时候使用XML代替ColdFusion或PHP(或其他替代方法)? What are some inherent advantages that would make it a more desirable option? 有哪些固有的优势使它成为更理想的选择?

For example, this is what the XML might look like: 例如,XML可能是这样的:

<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. 因此,在SQL Server中,每个数据库都具有1-1对应关系,每个数据类型都是一列。

Can someone please explain what the advantages of using XML to pull from the database are? 有人可以解释一下使用XML从数据库中提取的优点是什么吗? What exactly is happening here and why is it used over CF or PHP? 这里到底发生了什么,为什么要在CF或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? 也许有人会将Coldfusion用于插入,而xml仅用于视图?

XML is a data storage mechanism. XML是一种数据存储机制。 ColdFusion and PHP are data processing languages. ColdFusion和PHP是数据处理语言。 XML does not pull data from a database. XML不会从数据库中提取数据。 There are lots of reasons why people store data in XML. 人们使用XML存储数据的原因很多。 Some of the reasons are discussed here: Why would I ever choose to store and manipulate XML in a relational database? 这里讨论了一些原因: 为什么我会选择在关系数据库中存储和处理XML?

PHP and XML works with XML and so does ColdFusion. PHP和XML与XML一起使用,ColdFusion也是如此。 If you are looking to turn XML to something for an end user, you may want to consider XSLT . 如果您希望将XML转变为最终用户的东西,则可能需要考虑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. XML的目的是将数据存储在人类可读的平面文件中(XML在实体的文本命名中具有巨大的开销。而且,它不是人类可读的,它是一种传输介质),易于访问的形式。 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数据“存储”的方法非常健壮,并且一直在不断发展,包括Microsoft提出的“ XQL”提议-一种等效于SQL的用于处理XML数据存储的SQL提议。 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. XML非常简单,以至于它本身可以用作数据库–实际上,它非常灵活:您可以通过标签和不同的库数组无限地自定义XML实现。 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. 但是,XML有一个主要缺点:处理数据时,它比SQL慢,并且需要更多资源才能运行。

About ColdFusion & XML you can read HERE 关于ColdFusion和XML,您可以在这里阅读

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胜出的地方是,如果您有一个分布在20个表中的有关业务对象(比如一家酒店)的数据,并且您想将该数据发送给将数据组织成具有不同结构的16个表的人。 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. XML使您可以在一条消息中捕获有关对象的所有信息,这与数据库的设计无关,并且可能符合某些行业标准(例如OTA),并将其加载到设计完全不同的其他数据库中。

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. 另一方面,如果您的XML与SQL数据库设计的表和列紧密地联系在一起,那么您就不会从中获得太多价值。

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. IA / B使用缓存的XML产品文件测试了一个非常繁忙的站点,而不是缓存了一个非常大的查询,而缓存了较小的单个查询,到目前为止,XML每次都表现最差。 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. 如果您手头有一个数据库并且希望建立一个数据密集型网站,那么我强烈建议您避免使用XML,除非您出于某种目的将XML存储在数据库中。

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. 如果您确实正在为网站寻找平面文件系统,那么我会研究NoSQL数据库(例如MongoDB或CouchDB),其中有一些Coldfusion驱动程序和CFC已被编写为可与这些系统一起使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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