XML Menu


XML Elements




Elements are the basic building blocks of XML and all documents will have at least one element called root element that is the parent of all other elements. Once the XML prolog is finished you need to create the root element of the document. Everything else in the document lies under this element to form a hierarchical tree.

Syntax
<element-name attribute1 attribute2>
....content
</element-name> 

The elements in an XML document form a document tree. The tree starts at the root and branches to the lowest level of the tree. All elements can have sub elements (child elements).

<root>
  <child>
    <subchild>.....</subchild>
  </child>
</root> 

Underneath the root element can lie other elements. These nested elements can be used to show individual or repetitive items of data depending on what you are trying to represent. For example, your root element could be element underneath and the elements underneath could show the students’s characteristics, such as <name> and <rollno>.

<department>
  <student>
    <name>.....</name>
	<rollno>....</rollno>
  </student>
</department> 

XML Naming Rules

  • Element names are case-sensitive
  • Element names must start with a letter or underscore
  • Element names cannot start with the letters xml (XML or Xml, etc)
  • Element names can contain letters, digits, hyphens, underscores, and periods
  • Element names cannot contain spaces

Next Topic :XML Attributes