XML ElementsElements are the basis of XML documents. Indeed, an XML document is essentially a tree of elements. Elements are made of the following:
The following is a library element made up of two loan elements. Each loan in turn contains a member and a title element. loan elements have a date attribute, whereas member and title contain text: <library> <loan date="2000-03-27"> <member>Jack Smith</member> <title>XML by Example</title> </loan> <loan date="2000-03-12"> <member>John Doe</member> <title>Applied XML Solutions</title> </loan> </library> Unlike HTML, no element is predefined by XML. It is up to you, the developer, to create tags that are meaningful in your application. Element NameThe element name must start with a Unicode letter, followed by zero or more Unicode letters or digits. Also, spaces are not allowed. Names are case sensitive and cannot start with the three letters XML (upper- or lowercase). In the document, the element name appears within tags (start tag and end tag). The tags surrounds the content, as in <title>Applied XML Solutions</title> ContentIf an element has no content, it is said to be empty. Non-empty elements contain text, other elements, or a combination of both. In other words, elements can nest to form a tree. Empty elements have a simplified syntax where the slash ( / ) from the end tag migrates at the end of the start tag: <book isbn='0-672-32054-1'/> AttributeAn attribute is made up of a name and a value attached to an element. Attribute names follow the same rules as element names. Attributes appear in the element's start tag. The element name and its value are separated by an equal sign, and the value is located between single or double quotes. For example <book isbn='0-672-32054-1'/> or <loan date="2000-03-12"> <member>John Doe</member> <title>Applied XML Solutions</title> </loan> Predefined AttributesTwo attributes are predefined by the XML standard:
|