Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XML, what is it good for?

Tags:

xml

All right this is kind of embarrassing, but I am not sure what is the intended use of XML. That's right what is XML meant for, and NOT what is XML. I have used XML now and then over the years mostly for config files but this seems like a trivial use. I have also used it as inter-op format for data files but it doesn't look particularly efficient to me. I have minimal experience with web development so I was thinking may be it is useful for communication, but majority of the articles I read about XML were actually comparison between XML and JSON and not XML per se.

Update: So far my feeling (Based on this comment) is that XML was meant for generic data transfer, but after initial euphoria it has fallen in favor owing to its inefficient nature (and it is inefficient because it is generic) Further thoughts welcome.

like image 818
Gaurav Avatar asked Nov 19 '10 20:11

Gaurav


2 Answers

I try to make some summary of my experience with XML:

Pros

Human Readable Format:

Everybody can check its content by simply reading it. This makes it an easy to use and understandable form of communication. Even business people like it (as far as my experience with financial institutes for years), since they understand it, and they can check the messages for example in messaging systems easily. They alone can decide which system is wrong. Makes them happy :) Compare it with JSON. JSON is far from reader friendly I think, since closing brackets are harder to track than closing elements in XML. You have to page back to see what was the starting. You do not need any programming skill to understand XML. Even your grandmother can understand it after half hour.

Platform Independency:

It does not matter what type of language and platform you use, you will definitely will have a parser to read it. This makes it probably the best form of communication between heterogenous systems. See that people usually transfer XMLs over JMS queues, they send XMLs to web services, they map objects to XML documents before transport. XML is so basic stuff that there are no big issues with different parsers. They all understand XML.

Great Tools to Transform

You can use XSL and XSL-FO to transform your XML document to almost anything. HTML, PDF, TXT, CSV, some other XML doument and so on. XSL is quite powerful, since it is adjusted to the way of thinking of XML. It makes you think recursive, which I always liked as fun after object oriented programming. XSL is available for almost any platform. You can create reports and documents from pure data with XSL. You can map XML documents to programming objects easily with technologies like JAXB.

Great Tool to Validate With

XSD enable you to define some grammar for your XML documents. The schema itself is less user friendly than XML, but simplest constructions like occourance, parenthood, attributes and so on are easy to understand and use. So this is also a tool, that could be ok for business people. XSD is available for almost any platform.

XPath and XQuery

Both technologies let you traverse and query your XML. The advantage is the same as with XSL and XSD, that they are platform independent. XPath is so effective, that even for object trees apache created the equivalent of it: JXPath.

Cons

Verbosity

It can consume any disk space. XMLs make logs big and hard to read and fetch. On the other hand you can compress the logs. Even web services or JMS messages can be compressed to reduce the load of the channel. But even in this case compression is CPU and memory overhead. On the other hand in my experience XML and related technologies can shorten the development, and what you save in mandays is far enough for buying one more CPU. CPUs are cheaper than man.

Inefficient Usage

It is far from trivial that what kind of objects (XPath expressions, XSL templates, XSD schemas, XML parsers and so on) have what kind of lifecycle. What can be cached? A lot of people do not do it right to avoid thread safety problems. And this will lead you to horrible slowness. And I want to emphasize, that this is not the problem of the technology, but a misuse. A lot of people are stucked at old DOM parser which is an ugly thing. They abstracted some layer above it, and created proprietary APIs for XML handling, which is bad. Move on, use DOM4j or STAX or JAXB or anything standard.

False Freedom of Creating Something Special

A lot of companies created domain specific languages or horrible config files with XML. Since it is easy to parse and traverse, they created even interpreters for the brand new language. The language is stucked, and the planned development tools were never created. Do not ever use XML to make programs. It is not to be used for. Do not program in XPath, since it is not validated design time. Keep things in place. XML is mainly for transporting data in some standard form. Do not reinvent the wheel in XML. This would be a programmatic wheel chair for yourself and not a car.

Best tutorials about XML are at ZVON I think. Use them if you want.

like image 156
Gábor Lipták Avatar answered Oct 05 '22 04:10

Gábor Lipták


As a common form for passing data. It was the 1990s and mark up tags were all the rage!

There's a lot of flexibility and power, including the ability to validate an XML file; but I think it is interesting that a number of much more lightweight alternatives have popped up over recent years (eg. JSON). Ie. being able to easily read/write data in a human-readable form appears to be more important than all that validation stuff, for most applications.

like image 34
winwaed Avatar answered Oct 05 '22 06:10

winwaed