简体   繁体   中英

XML vs Databases

So I'm starting to learn XML. It seems like a simple flat file data system of which you can view output by using a server side language of your choice and some parsing. I don't really see the benefit to using XML over storing values in a database and doing the same kind of parsing. I mean it would seem that databases would be faster.

So what can you really do with XML that you can't/shouldn't do with a database? Is XML really that useful?

So what can you really do with XML that you can't/shouldn't do with a database? Is XML really that useful?

XML is an interchange format first and foremost. It allows you to transport structured data between programs, servers, or people, and retain a common parser and schema system.

XML of course can be horribly misused or overused.

This question is to broad (ie there are too many aspects in which they differ), yet main reason for XML is not even about data storage. It was designed as ultimate common platform for data exchange with defined rules how data is organised. Thus you can read/write valid XML on almost every platfrom and language.

XML is designed to be more human readable. XML can be opened easily in a text editor and read. Some XML readers can support folding, which also helps with getting a hierarchical organization to your data.

If you're processing files that's a different story. I think databases often have the option of exporting to XML.

You can carry your datas from one type database to another (example from MS-SQL to MySQL) by using XML.

Or sending datas from an application to another, which is used on many web applications.

I think it can be very useful for this.

I think it is comparison of apples to oranges... There are a lot of usages of XML but it is not primarily used for storing data. It is very loosely coupled data structure when compared to databases.

One of the many usages of XML, which I encounter with very frequently is exchanging data from one program to another. Because it is very simple format one can create an XML file in Java program and other can parse(read) the xml file in VB/C#/Python/Cocoa or any other language.

One such use of XML is Webservices where client programs can call(Execute) code residing on servers, where requests and response both are in XML.

So one can say that strong feature of XML is interoperability.

On the other had databases are mainly used for storing and retrieving data, databases are extremely powerful to do fast retrieval/insertion of values in tables where XML will immensely fail because most of the time XMLs have to be read serially as oppose to tables residing in databases.

XML can contain highly complex tree data structures that cannot be easily represented in relational databases.

XML is also useful for representing documents (Word docs for example or HTML).

The thing that's so appealing about XML is that it is quite simple to create.

Python is a great language for converting text files into XML for example.

XML vs databases is a false dichotomy, because you can store XML in databases. Though it's true that a simple XML document can sometimes be used for an application that would otherwise have needed a database.

If you're dealing with documents (like articles in technical journals) then your only real choice is between XML and some proprietary equivalent. This of course is the problem that XML was originally invented to solve.

XML is also used extensively for data messaging. It supplanted EDI and ASN.1 in this role because it can handle all the complex data that EDI and ASN.1 can handle, but is itself much simpler. More recently we've seen JSON taking over some of this role, especially for "private" (as distinct from standardised) protocols, because JSON is simpler still, and works better with general-purpose programming languages.

XML, like any successful technology, has also been used extensively for problems where it isn't really needed. That's not a misuse, any more than it is a misuse of this forum to send a plain text message in a field that is capable of holding richly formatted text, or to ride my bicycle on a road that's engineered to take 40ton lorries: once the technology is in place, you might as well use it.

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