XML 1.0 and Namespaces
XML 1.0 and Namespaces in XML provide a tag-based syntax for structuring data and applying markups to documents. Documents that conform to XML 1.0 and Namespaces in XML specifications may be made up of a variety of syntactic constructs such as elements, namespace declarations, attributes, processing instructions, comments, and text. This chapter provides a description of each of the structural elements in XML along with their syntax.
1.1 Elements
<tagname></tagname> <tagname/> <tagname>children</tagname>
Elements typically make up the majority of the content of an XML document. Every XML document has exactly one top-level element, known as the document element. Elements have a name and may also have children. These children may themselves be elements or may be processing instructions, comments, CDATA sections, or characters. The children of an element are ordered. Elements may also be annotated with attributes. The attributes of an element are unordered. An element may also have namespace declarations associated with it. The namespace declarations of an element are unordered.
Elements are serialized as a pair of tags: an open tag and a close tag. The syntax for an open tag is the less-than character (<) immediately followed by the name of the element, also known as the tagname, followed by the greater-than character (>). The syntax for a close tag is the character sequence </ immediately followed by the tagname, followed by the greater-than character. The children of an element are serialized between the open and close tags of their parent. In cases when an element has no children, the element is said to be empty. A shorthand syntax may be used for empty elements consisting of the less-than character immediately followed by the tagname, followed by the character sequence />.
XML does not define any element names; rather, it allows the designer of an XML document to choose what names will be used. Element names in XML are case sensitive and must begin with a letter or an underscore (_). The initial character may be followed by any number of letters, digits, periods (.), hyphens (-), underscores, or colons (:). However, because colons are used as part of the syntax for namespaces in XML, they should not be used except as described by that specification (see Section 1.2). Element names that begin with the character sequence xml, or any recapitalization thereof, are reserved by the XML specification for future use.
Examples
An element with children
<Person> <name>Martin</name> <age>33</age> </Person>
An element with a tagname of Person. The element has children with tagnames of name and age. Both of these child elements have text content.
An empty element
<Paid></Paid>
An empty element with a tagname of Paid
Empty element shorthand
<Paid/>
An empty element with a tagname of Paid using the shorthand syntax