The Hyphe about XML

XML : What It Is, And What It Is Not!
What it is:
XML is a structure for data formatting, no more and no less.
Imagine this scenario:
Some corporation ABC has to upload data from text files and has a format like this:
01:Hanks,Tom:7850:Assistant Manager:B
1. This format does not make any sense to any one except the program that ABC corporation uses to upload information.
2. The program has to specifically read this formatting and interpret what the first value is, the second value and so forth.. and load it into a database.
3. Creating such a file is also a menial and error prone task.
4. A missing colon could create havoc. Custom written programs would have to check the health of the file structure to know if it is malformed or not.
Compare and contrast with this structure:

<employee>
<id> 01 </id>
<name> Hanks, Tom</name>
<salary> 7850 </salary>
<position> Assistant Manager </position>
<grade> B </grade>
</employee>

1. Any one can interpret what this is all about
2. Programs can use XML-specific APIs to read data more easily
3. XSL tranformation makes it easy to convert data from one structure to another (for instance from xml to pdf or html)
4. XML Validators (pre-written generic programs) can check malformed-ness, so there is no need for check-sum, byte counting and other primitive methods of checking if data is valid.
What it is not:
1. It is not a programming language (although XSLT is a programming language, or rather a transformation language that converts from one text format to another).
2. It is not specific to any programming language including java. Any language that can do input/output (read and write text) can work with XML. This is what makes XML the unifying bond between disparate systems written in different programming languages.
3. It is not the optimized way of storing data. If you see the structure, the data is not compact. For example if data about 10 employees is to be stored each of the tags (id, name, etc..) would be repeated ten times.
4. It is not meant to replace traditional relational databases. XML cannot deal with too much data. It is after all, just text that is processed sequentially.
It is easier to work on XML with the java language because java has a good set of APIs that are prewritten, that can be utilized for parsing, creating and validating XML files.
Another advantage that java has is that XML files can be mapped to java classes easily. For example, the above example can be mapped to the java class:

public class employee {
String id;
String name;
float salary;
String position;
char grade;

getId(){blah..blah…}
setId(){blah..blah…}
And so on and so forth…
}

Where it is useful:
There are two situations that XML is used:
1. Small amounts of data – interchange between disparate systems. This interchange can be real-time or off line. Real-time data interchange using XML is what soap/ web services is all about.
If systems that need to communicate in real-time are both in java, we might as well use RMI or CORBA to pass java classes into remote methods.
2. As configuration files
In the traditional days, configuration files that hold data was of this structure
key=value
eg
weight-unit=kilograms
temperature-unit=celsius
In XML this can be replaced with a structure that looks like

<weight-unit> kilograms </weight-unit>
<temperature-unit>  Celsius </ temperature-unit>

For example that is how ejb engines store data for EJB configuration. (deployment descriptors)
Because of the ease of creating and manipulating XML files, most EJB engines provide a GUI front end that allows you to enter data into screens that are then transformed into XML format and stored, and will then be used for getting values necessary for the ejb engine to work.

About cuppajavamattiz
Matty Jacob - Avid technical blogger with interests in J2EE, Web Application Servers, Web frameworks, Open source libraries, Relational Databases, Web Services, Source control repositories, ETL, IDE Tools and related technologies.

Comments are closed.

%d bloggers like this: