8

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.

Community
  • 1
  • 1
Gaurav
  • 794
  • 2
  • 11
  • 32

11 Answers11

11

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.

Community
  • 1
  • 1
Gábor Lipták
  • 9,646
  • 2
  • 59
  • 113
7

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.

winwaed
  • 7,645
  • 6
  • 36
  • 81
  • I'm not aware of anything (other than JavaScript itself of course) but I am far from being a JSON expert. – winwaed Nov 19 '10 at 20:54
3

Xml is human readable and standardized. Every language has some type of XML parser.

Community
  • 1
  • 1
Byron Whitlock
  • 52,691
  • 28
  • 123
  • 168
2

An over-simplified explanation: It's just a convenient way to encode data that is easy to read for both humans and machines.

espinchi
  • 9,144
  • 6
  • 58
  • 65
  • @espinchi Yes but that is definition of XML, not its purpose. – Gaurav Nov 19 '10 at 20:33
  • 2
    XML isn't easy to read for machines. That said, every language has an xml parser lib so it is very convenient for the programmer. – Byron Whitlock Nov 19 '10 at 20:34
  • @Guarav, the purpose is to facilitate a convenient way to encode data that is easy to read for both humans and machines. – Klaus Byskov Pedersen Nov 19 '10 at 20:35
  • 4
    XML isn't easy to read for humans. Every time I open an XML file in an editor, to my eyes, content gets lost in sea of tags. – darioo Nov 19 '10 at 20:38
  • 1
    @darioo: Good point, but I'd rather have that then position-delimited files. – FrustratedWithFormsDesigner Nov 19 '10 at 20:40
  • 2
    XML isn't all that easy to read for humans either. Tags and data share all the letters and numbers in the English language, meaning words can look almost exactly like tags. Add in support for namespaces, XSLT, and a bunch of other things that make what you see *not necessarily* what you get...and it quickly gets overwhelming for anyone naive enough to read arbitrary XML with a text editor (cause "after all, it's just text!"). One's only hope for reading arbitrary XML is whitespace, and/or a text editor with syntax highlighting, and/or an XML parser. – cHao Nov 19 '10 at 20:47
2

XML is meant as a format to represent data - a format that humans can read and machines can process.

Really, that's it.

As for its "intended use": well, that's a bit subjective. It can be used for serialization, data-interchange, document markup, or whatever. Really, it can be used for almost any purpose involving digital data.

Charles Salvia
  • 52,325
  • 13
  • 128
  • 140
1

XML is actually a container where you can put structured text data, and that covers a lot of different possible uses, like text with semantic structure, for example. The structure can also be seen as a tree, so you can hierarchically organize things.

It can be validated against formal grammar rules (DTD, XSD...), transformed in another tree structure (XSLT), data can be extracted by different means, like query languages (XQuery), XML can be built from a tree (DOM), and much more.

These technical possibilities open to a lot of features in various domains, like data storage, network communication, process organization (here you find your config files) and so on.

Alexis Dufrenoy
  • 11,784
  • 12
  • 82
  • 124
0

XML is great for laying out graphical user interfaces. HTML, Flex, Pivot, etc.

Jeremy
  • 22,188
  • 4
  • 68
  • 81
  • Seriously? Is it really such a different concept that it doesn't relate? Give me a break... – Jeremy Nov 19 '10 at 20:58
0

XML is a standardization for communication. While it is a bit more verbose for instance than using text files or binary files, the advantages outweigh the disadvantages. XML is very extensible and all you need is an XML parser on any platform and you will be able to read XML data produced from anything.

What the XML data means is another story though since XML allows you to create tags and attributes that fit your data. The alternative is that you create your own format for this data and than anything that would need to consume your data would have to know how to parse it.

Casey
  • 12,070
  • 18
  • 71
  • 107
0

XML's strength is in human readablity. Data which needs a structured, human-readable layout is what it is really for. Using it for config files can make a lot of sense in this manner. Also, UI layout (Flex's MXML, etc) is a popular are legitimate use, in my opinion.

However, it is very verbose, as you mentioned. This makes it very inefficient to transmit in an uncompressed form.

Courtney Christensen
  • 9,165
  • 5
  • 47
  • 56
0

As others have said, XML is a good standard for exchanging information between various applications. It is basically Esperanto for data exchange.

One thing that nobody likes about XML is its verbosity. A human will get lost in all those tags if there are more than 2-3 levels of indentation. And no, you don't stop seeing all those tags after some time like people do with Lisp's parentheses.

Also, XML has a very "enterprisey" feeling. That means, big corporations love it because it's a standard. But that doesn't mean it's good for every situation. And don't think parsing it is fast because hardware exists just to parse XML faster than using just software...

darioo
  • 46,442
  • 10
  • 75
  • 103
0

I would like to add that it is queryable. We receive XML files every hour that contains prices for over 100 locations. I needed to get all of the prices from those files for a single location.

I loaded the files into a table in SQL Server and then I could select the prices for the location I was interested in. I blogged about this HERE.

Another advantage is that it is easier to deal with than fixed width data files that we used to have to deal with. Before if you added a column to the end of your data file it would usually break the process that read that file in. If you had 10 different companies reading the file than all 10 would have to change on the same day. Now you can add a new element and the clients can update when they want to if they are interested in that element.

JBrooks
  • 9,901
  • 2
  • 28
  • 32