XML Elements
<p>The first step in learning about how information is structured in an XML document (the word “document†will be used to refer to information and its organization, typically stored in a disk file) will be to learn the syntactic components. The most basic component in XML is called an “<b>element</b>†or “<b>node</b>â€: both are used inter-changeably in documentation.</p> <p>An <b>element</b> consists of a “name†assigned to it, as well as the content which the name describes/defines. One can also use the word “<b>tag</b>†to describe a name, in conformance with HTML terminology. As it turns out, “tag†is popular universally, and in this document, we shall stick to this terminology. Each element has an opening tag, content (optional) and a closing tag. Sometimes, a single tag might be enough to describe an element, especially when no meaningful content can be stored between the opening and closing of a tag. Learning by example is the best way, so we will see a few below.</p> <p>First let us look at what an element typically looks like:</p> <p><name>Babe Ruth</name></p> <p>The parts of this element are as follows:</p> <p> • <<b>name</b>> is the opening tag, and “name†is the tag-name</p> <p> • “Babe Ruth†is the content of the element, and here it is a character string</p> <p> • </<b>name</b>> is the closing tag: note the forward-slash “/†at the beginning</p> <p>Another example of an element is: <drinking minor=â€yes†/></p> <p> • Note here that there is only one tag, which both opens and closes the element; the tag name is “drinkingâ€</p> <p> • “minor†is called an “<a href="/courses/video/47/368/Attributes.html">attribute</a>†or “property†of the element. It has the value “yes†in this case.</p> <p>XML, unlike HTML, is a case sensitive markup language. The content of an element can be a character <a href="/courses/video/4/154/Strings-As-Our-First-Variable.html ">string</a>, an alphanumeric string, a <a href="http://02geek.com/courses/video/4/156/Numbers-As-Our-Second-Variable.html">number</a> etc.; it can be any type of information that is normally used by people and applications. When it comes to tag names, the following exclusions apply:</p> <p> • The word “XML†or “xml†cannot be used as a tag name… it is the ONLY reserved keyword in an XML document</p> <p> • A tag name or <a href="/courses/video/47/368/Attributes.html">attribute</a> name cannot start with a numeric character; for example, “32age†is not a valid identifier (another name for tag or attribute name,) whereas “age32†is valid.</p> <p> • You can't have a space character within an identifier name: for example, “player name†is not a valid identifier, while “player_name†is.</p> <p>This ends the introduction to syntax and naming of tags and attribute names.</p>