February 5, 2012, Sunday, 35

XML briefly explained

From E-Parliament Wiki

Jump to: navigation, search

A Quick Guide to XML Tags, the DTD and the XML Schema

XML is definitely a buzz word these days. Lots of Web sites, magazine articles and even newscasters mention XML data. But what is XML and why is it so popular? Let's take a look. XML stands for Extensible Markup Language. It is a language used by computers to transmit data. It is particularly useful for communication between different types of information systems that would normally not be compatible with each other. One of the main strengths of the XML language is that it is fairly easy for humans to read and understand.


XML Tags
XML uses tags to encode data. Tags are words or phrases enclosed inside a "less than" and a "greater than" sign. For example, to encode a phone number, you might use the tag <phone number>. In XML, tags are custom, so you are not confined to using to describe phone numbers. Instead, you could choose <phone>, or <pnum>or even <fred> if you wanted to. The only important thing is that you must always use the same tag to describe similar content inside an XML document. So if you use <phone number> once, you must use it every time within that document to encode phone numbers.To actually encode a phone number, or any other piece of data, it must be enclosed between an open tag and a close tag. A close tag is simply denoted by adding a slash at the front of the tag. Here is an example:

< phone number > 555-786-4763 < /phone number >

It is possible to associate several pieces of data with each other by enclosing them in another set of tags. For instance, if you have phone numbers and names for several people (customers, let's say), and you want to associate each name with a phone number, you can enclose both the phone number and the name inside another tag, like this:

< customer >
< name >John Smith< /name >
< phone number >555-875-3321< /phone number >
< /customer >

Now I could keep adding customers to this file, and every customer would have a name and a phone number associated in the same way. Of course, you can name the tags anything you want, as long as you are consistent. Now this data can be shared easily between computers, simply by telling
both computers what tags were used.


DTD's and XML Schema's
DTD's, and their newer replacements, XML Schema's, both serve the purpose of explaining the tag structure in an XML file. Since XML tags are custom and can be different for every document, without a DTD or XML Schema, the computer or device receiving an XML file would have no idea what it was looking at. The DTD or Schema lists all of the tags used in the document and explains the relationship between tags. So in the XML example above, the DTD or Schema would constrain the document to include only the <customer>, <name> and <phone number> tags. It would also explain that the <name> and <phone number> tags belong to the <customer> tag and that each <customer> tag can only have one <name> and one <phone number> tag.The actual language of DTD's and XML Schema's is far more complicated and hard to read than XML itself, so I will not go into detail in this article. The greatest strength of XML, however, lies in the use of DTD's and Schema's. In the past, computers would store data in a proprietary way. For instance, phone numbers might be stored in a field called "phone_number" in one computer. When that computer tried to send data to another type of computer or application, the receiving computer might call phone numbers "pn_nmbr." In this case, there would be no way for these computers to communicate without a translation program. And then you would need to have translation programs for every type of computer.


With DTD's and XML Schema's, the data can be marked up using whatever tags the creator desires. Then when the data is sent, the receiving computer needs only to look at the DTD or Schema to be able to translate the data. A much better solution! And that is why XML is so popular now. With it, data can be transfered easily between any two computers, or even between other devices, like phones or television set-top boxes.


References

  1. XML Explained: A Quick Guide to XML Tags, the DTD and the XML Schema, Andrew Goodrick, 2007