There's no better way to learn about XML than to start looking at it. If you've never used XML, but you've written some HTML, this should look somewhat familiar.
Here's a simple chunk of XML for you to enjoy:
<?xml version="1.0"?> <hello> <there> <!-- Finally, real data here. --> <world target="everyone">think XML</world> <totalCount>694.34</totalCount> <goodbye /> </there> </hello>
Hey, I didn't say it was going to be interesting. As I mentioned before, it's just data, but it is useful data, and here's why:
This is clear from the first line, which always starts with
<?xml . . . . This line also indicates the XML version number, which tells XML processing routines (parsers) to adjust behavior if needed. That's foresight.
XML is a hierarchical data structure. That is, you can have data elements embedded inside other data elements to any depth you want. Every element is bounded by a set of tags. In this sample, the tags are
goodbye. Tags always appear inside <angle brackets>, and always appear in pairs, as in
<hello>...</hello>. (This is where The Rule, "If you open it, close it," comes in.) Don't forget the
/ just before the tag name in the closing bracket. This syntax lets you organize your data into specifically arranged named units. For tag pairs that have nothing in between them, you can use the shortened syntax
/>, as I did with the
goodbye tag. By the way, XML tags are case-sensitive, ...