Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is XML good for and when should i be using it?

I'm curious, I've been developing pretty powerful websites/web apps, and I've never learned XML, even odder I've never really felt the need to. It's not like curl or Prepared Statements where, before knowing what they did and how they worked, I had a feeling 'there's got to be an easier way to do this!' or 'there's got to be something designed for this!'.

Currently I work with MySQL and JSON and I don't have this feeling of 'I need to learn that' (XML), this must be wrong!

I'm really interested to hear some compelling arguments for XML, and learn about things which it can do beter than JSON or MySQL (or some other aspect of web dev) and when i should be using it!

like image 458
Haroldo Avatar asked May 20 '10 08:05

Haroldo


People also ask

What is the main benefit of XML?

XML uses human, not computer, language. XML is readable and understandable, even by novices, and no more difficult to code than HTML. XML is completely compatible with Java™ and 100% portable. Any application that can process XML can use your information, regardless of platform.

What is XML used for today?

XML is used extensively in today's online world – banking services, online retail stores, integrating industrial systems, among other things. Create interactive web pages, store and render content data to the user based on processing logic using the XSLT processor. XML requires a processing application.

What is an XML file and do I need it?

To summarize: An XML file is a file used to store data in the form of hierarchical elements. Data stored in XML files can be read by computer programs with the help of custom tags, which indicate the type of element. Let's take a look at some use cases for this extensible language below.


4 Answers

JSON is very lightweight which makes it better suited for passing data around to the front end.

XML has descriptive tags that (I personally find) make it easier to read in a raw format. If I wanted to have any sort of settings file that is loaded in from my program, i would have it in an XML file format.

That's my idea of it anyway, but i'm sure there are much more in-depth reasons for choosing one over the other. Of which i am not experienced enough to list :)

However i did find a couple of sites that make some good points.

http://ajaxian.com/archives/json-vs-xml-the-debate (Some good points in the comments)

http://webignition.net/articles/xml-vs-yaml-vs-json-a-study-to-find-answers/

like image 132
4imble Avatar answered Sep 28 '22 00:09

4imble


XML is useful for storing heterogeneous tree structures, in situations where general purpose tools can be applied to them and some redundancy is desirable. If you are doing modern web development, there is a good chance you are producing XHTML rather than HTML, and are producing RSS or Atom, so you should already using be it. The most common RDF formats use it.

JSON is a bit easier to work with for data on the web, but hasn't got the same feature set - you can't have attributes in JSON so there is no implicit difference between data and meta-data, and you don't have processing instructions or the ability to create entities for repeated chunks of text. On the other hand, many uses of XMLl don't use those features either. SQL databases have a fixed schema, and do not represent trees well.

Mostly XML is used for interoperability.

like image 44
Pete Kirkham Avatar answered Sep 27 '22 23:09

Pete Kirkham


One of the advantage of XML over other serialization formats is the number of tools available. The other is the ability to formalize the description of you data (XML Schema).

The availability of tools lets you use XML editors, transformers, visualizers, ... For example, where I work, we have the communication team using an XML editor to edit content and metadata. They are not technical enough to write JSON by hand (or XML), but it is very easy to give them a template with a nice generic frontend to edit the needed documents.

Having a way to describe the format (XSD, DTD, Relax NG, ...) means that you can also automagically validate your documents. It also serves as a pretty good documentation of what is allowed and what is not in your documents.

like image 36
Guillaume Avatar answered Sep 27 '22 22:09

Guillaume


XML is simply for storing messages in a structured way that is (ostensibly) application agnostic. This is all it is. Said another way, XML offers a way to preserve semantics (meaning) of data when communicating between different applications. It's also popular as a configuration format since (1) a config file is just a message between different application sessions* and (2) almost every language has mature, standard XML libraries.

*you can also think of this as just a degenerate case of communicating between applications.

like image 21
Rodrick Chapman Avatar answered Sep 27 '22 22:09

Rodrick Chapman