XML Element

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

xml element

XML is a markup language that is used to store data in a self-explanatory manner. Making the data "self-explanatory" comes about by containing information in elements. If a piece of text is a title then it will be contained within a "title" element.

xml tag

A tag is just a generic name for a . An opening tag looks like , while a closing tag has a slash that is placed before the element's name: . From now on we will refer to the opening or closing of an element as open or close tags. All information that belongs to an element must be contained between the opening and closing tags of an element.

xml attribute

Attributes are used to specify additional information about the element. It may help to think of attributes as a means of specializing generic elements to fit your needs. An attribute for an element appears within the opening tag.

If there are multiple values an attribute may have, then the value of the attribute must be specified. For example, if a tag had a color attribute then the value would be: red, blue, green, etc. The syntax for including an attribute in an element is:


In this example we will be using a madeup XML element named "friend" that has an optional attribute age.

XML Code:



element review

  • Elements are used to classify data in an XML document so that the data becomes "self-explanatory".

  • Opening and closing tags represent the start and end of an element.

  • Attributes are used to include additional information on top of the data that falls between the opening and closing tag.