Do you cringe when you hear the words "XML"? Are you just not sure what the heck this acronym is all about? Not to worry! In this article, Liviu introduces us to XML, the various ways it can be created and parsed, as well as a brief introduction to XML and the way it came to be.
XML Basics - Part One - The Need for XML (Page 3 of 5 )
Just like humans, computer programs were puzzled when they “spoke” different languages – and since every single company insisted on using their own language, there was a need for common ground – neutral to all the existing ones, but which can be adapted – to serve all these languages.
That’s where XML stepped in – through it’s (nearly) unbound structure, it allows us to describe most (if not all) data formats known in such a manner that it can be understood by other XML-enabled programs without the need for these programs to be aware of the actual contents of the file. Even more so, XML doesn’t limit you to representing only one type of data (e.g. word processor, spreadsheets, vector graphics etc.) – you can represent anything with XML, assuming you have defined a “grammar” to do so. Also, as there are XML parsers for nearly every single programming language, plugging XML into your application is (nearly) an easy task; and as long as the program you are exporting data for can parse XML, it should be able to understand your data. Note the term “should” in the previous sentence!
Let’s consider one example: suppose you write a program to export employee file details from your HR system in XML. A typical “record” in XML could look like this:
This is a valid XML tag – it declares an element of type Employee, which has three attributes: name, surname and birthday. All other programs that need to read such data will look for an Employee tag and read these 3 attributes. However, take the following one:
It is a valid structure and it represents the same data! Even more so, try to interpret this data in the USA (the author of this article is based – at the moment – in Europe, where the data format is day/month/year) and you’ll find out that such a birth date is invalid!
If that is the case, how would another application that needs to make use of this data “know” how to interpret it and make sure that this information is valid – and therefore no errors would be input into the system?