What is XML
From LoveToKnow Web-Design
"What is XML?" comes the cry from web designers everywhere. Comfortable with years of HTML, having the Web 2.0 revolution continue to change web standards can be frustrating. The growth of media, CSS and many other new technologies makes it hard to keep up.
What is XML? And Why?
XML stands for Extensible Markup Language (the question as to why it's not "EML" is lost to the ether). It is a method of organizing information in a semantic way – that is, a way that is intuitive to the programmer, the designer, and even sometimes the end user. It answers some of the demands of the flood of data, much of it personalized, that has formed the basis for the web 2.0 experience.
What is XML good for? By putting the information into a specific and relevant framework, the data is able to be separated from the style and interface used to access it. This means that when a user looks at a page on their mobile phone they only need to get the information that can quickly and accurately be put on the smaller screen, whereas a home computer user with several monitors can get more complete information laid out on the screen in an aesthetic and efficient design.
Cascading Style Sheets are often used hand with XML in order to accomplish this, with one style sheet for each interface, all drawing from the same XML document.
The XML Document Type Definition
Here is an example of an XML document:
<?xml version="1.0"?> <dinner> <vegetable>corn</vegetable> <meat type="beef" cut="sirloin" cooked="medium"/> <dessert>ice cream</dessert> </dinner>Looking at this, if anyone was asked "what was for dessert?" it would be fairly easy to discover the answer. In addition, it is easy to see how other dinners could be added – each with the elements of vegetable, meat, and dessert.
But what is XML's most strong advantage is that it is extensible. This means that if there is a dinner with another course – say, an appetizer – it is easy to add this in:
<?xml version="1.0"?> <dinner> <appetizer>stuffed mushrooms</appetizer><pre><vegetable>corn</vegetable> <meat type="beef" cut="sirloin" cooked="medium"/> <dessert>ice cream</dessert> </dinner>
There are some other aspects of the code for XML that are illustrated by this small example.
- XML tags need to be closed, just as HTML tags are, with a backslash ( / ) before the closing tag.
- There can be "empty" elements such as the "meat" above, given attributes (in this case type, cut, and cooked) which are then simply ended with a backslash and carat (/>)
- All of the "children" of an element (called a "node") need to be within the opening and closing tags of the "parent" node, not overlapping.
- While each node can be called anything, it cannot begin with a number or the letters XML. So, while "XMLDefinition" would not be allowed, "WhatIsXML" would be.
What is XML that is Well-Formed?
While XML is immensely flexible in terms of content, the syntax of a workable XML document is very strict. As data becomes more and more complex, and the parent and child nodes have more and more elements and attributes, it can become harder and harder to keep track. However, syntax becomes all the more important then.
The reason why has to do with something called "parsing." While the words used for elements are intuitive for the programmer, to the computer it is just another piece of data. In order to let the computer easily process how all the elements, attributes and nodes relate to each other, it has to drill down past the layers of tags. If a tag is not closed properly, there is no way for the program to know where the data belongs. For example, if the "vegetable" tag in the example above was left open, the vegetable might seem to be a medium-cooked sirloin corn.
Most programs such as PHP that process XML data will simply check that all tags and syntax are correct and then return a "XML not well-formed" error if there is a problem. Some web design software programs such as Dreamweaver will also have interface assists that complete tags and check syntax as the code is written.
The answer to the question "what is XML?" is not a simple one, but understanding it is nonetheless an essential skillset in any web designer's toolbox.
Learn More
This page has been accessed 170 times. This page was last modified 04:54, 6 July 2008.
© 2006-2008 LoveToKnow Corp.
