XML (extensible markup language) allows data to be formatted and transferred across disparate systems. It has become a universal method for data transportation as it is completely platform independent, and can be parsed by almost any programming language.
The basic building block of XML is an element tag. Within an element tag, you will find text, attributes and other element tags.
Consider this basic example of a well-formed XML document:
A Christmas Carol "Charles Dickens" Fiction 1843 86
The root element tag 'books' contains a child element tag 'book'. The 'book' tag contains the child elements title, author, genre, year, pages and link. Each of these elements contains a string of text that gives details about the element.
XML can be sensitive to characters that are interpreted by the XML parser as XML code, rather than text.
To counter this problem, XML offers Entity References. Notice that the text inside the author element is enclosed with:
"
This creates quotations around author's name. If we were to just use "" the XML parser would throw an error as it would interpret the quotes as part of the XML code.
Some other common entity references are:
< = < > = > & = &
Another method for including special characters in XML is CDATA. CDATA text is ignored by the XML parser and displayed as is. To use CDATA you must wrap your text in:
.
Notice in the example above the 'link' text is wrapped in a CDATA tag. This allows us to use the ampersand sign in the link without a entity reference.
Just like HTML tags, XML elements can contain attributes. Notice that the year element has an attribute that specifies either AD or BC for the date.
This covers the basics of creating an XML document. What happens from here really depends on what you intend to do with the XML, or where you plan to transport it.





