XML, or Extensible Markup Language, is basically a standard for cross script data storage and transmission. It is very similar to HTML in that it uses tags to delineate information, but very different in that it has no implicit visual structure; it is purely for storing and accessing information. That's right: it does nothing on its own. This was very mind boggling to me while I was learning it, because nobody mentioned that fact in the lessons I read. So there you go.

As mentioned earlier, XML is comprised of tags which the user can create and name him or her self. These tags contain text that, by convention, elaborate on the name of the tag. So if you want to create an XML tag that contains someone's name, you need only do this:

<name>Joseph Smith</name>

If you're so inclined, you can name the tag something completely unrelated to the information it contains, but why would you want to do that? Anyways, you can see that the name tag has both an opening and closing tag. In XML, all tags are required to have a corresponding closing tag. You can also nest tags -- again, you can name them whatever you want, but for readability most choose to use logical nomenclature.

<person>
    <name>Joseph Smith</name>
    <age>26</age>
</person>

Nothing too complicated here. This brings up the premise of relationships between the tags, which are generally called nodes. The person node has two child nodes: name and age. Inversely, the person node is a parent node of name and age. Lastly, name and age are sibling nodes. Incidentally, the person node is also the root node in this case. The root node is the most "senior" node in the file -- that is, it has no parents. In XML files, there can only be one root node.

XML nodes can also have attributes, but they will only needlessly complicate scripts that try to use them. But I'll address them anyways, since you'll inevitably have to deal with them at some point. An attribute, like in HTML, is simply an additional piece of information that is contained within the opening tag. I'll take this opportunity to make our hypothetical XML file a little bigger as well.

<people>
    <person>
        <name prefix="Mr">Joseph Smith</name>
        <age>26</age>
    </person>
    <person>
        <name prefix="Ms">Josephina Smith</name>
        <age>26</age>
    </person>
</people>

First off, our root node is people, of which there are two. Remember, an XML file can only have one root node! Next you'll notice the attributes in the name nodes. Mind you, you don't have to add an identical attribute to every tag of th same name (i.e., if one name tag has the attribute "prefix", you are permitted to have another name tag without that attribute). You are also permitted to have more than one attribute in a single node. They also must be quoted, even if they're only a single word (preferably double quoted, but I don't think it will break the file to have single quoted attributes). All that said, I recommend simply not using attributes. You should instead create another node for the attribute.

An additional note is that XML files must have properly nested node structure. Compare this example to the one above.

<people>
    <person>
        <name prefix="Mr">Joseph Smith</name>
        <age>26</age>
    <person>
    </person>
        <name prefix="Ms">Josephina Smith</name>
        <age>26</age>
    </person>
</people>

You'll see that a second person node is opened before the first one is closed. This is illegal. Simple enough, eh?

Finally, no XML file is complete without a header that tells the browser just what the heck it's looking at. If an XML file contains this and follows all of the other rules I've discussed in this lesson (one root node, a closing tag for every opening tag, quoted attributes, properly nested node structure), the file is considered "well formed" and can thus be used in the lessons to follow. Here's the complete XML file that we used in this lesson (the only addition is the header).

<?xml version="1.0" encoding="UTF-8"?>
<people>
    <person>
        <name prefix="Mr">Joseph Smith</name>
        <age>26</age>
    </person>
    <person>
        <name prefix="Ms">Josephina Smith</name>
        <age>26</age>
    </person>
</people>